From: Richard on 31 Mar 2010 06:55 Hi I have a form.doc (A) which I need to e-mail to 3rd parties without the code to reduce file size. Code has been written to copy the text from the form to a new document (B), which I then need to save to enable it to be e-mailed via Outlook. The original document (A) is still the activeDocument, but to save the new one (B), (B) needs to be the activeDocument for the code: ActiveDocument.Save to work. So, How do I make (B) the ActiveDocument (Which is not saved) & later make (A) the activeDocument to perform further tasks? Templates (.dot) are deliberately not being used as references get lost when files are moved in a big organisation. All contributions gratefully received. Thanks - Richard -- Richard
From: Jay Freedman on 31 Mar 2010 07:29 There is no need to make any particular document active in order to save it. Word VBA has the idea of a Document object, and you can declare a variable of type Document that can be used regardless of whether it's "active" (has the focus). Start out with code like this: Dim DocA As Document, DocB As Document Set DocA = ActiveDocument Set DocB = Documents.Add ' new blank document ' copy text from DocA to DocB as needed DocB.Save ' <= doesn't matter which document is active DocA.Activate ' if necessary ' more processing Also, I think your description is inaccurate in one respect: When you make a new document, it automatically becomes active, and the document that was active at the time (DocA) is not active. Your statement "The original document (A) is still the activeDocument" should not be true. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Wed, 31 Mar 2010 03:55:01 -0700, Richard <Richard(a)discussions.microsoft.com> wrote: >Hi > >I have a form.doc (A) which I need to e-mail to 3rd parties without the code >to reduce file size. > >Code has been written to copy the text from the form to a new document (B), >which I then need to save to enable it to be e-mailed via Outlook. > >The original document (A) is still the activeDocument, but to save the new >one (B), (B) needs to be the activeDocument for the code: > >ActiveDocument.Save > >to work. > >So, How do I make (B) the ActiveDocument (Which is not saved) & later make >(A) the activeDocument to perform further tasks? > >Templates (.dot) are deliberately not being used as references get lost when >files are moved in a big organisation. > >All contributions gratefully received. > >Thanks - Richard
From: Greg Maxey on 31 Mar 2010 07:34 Sub ScratchMaco() Dim oDocA As Word.Document Dim oDocB As Word.Document Set oDocA = ActiveDocument 'Set the active document Set oDocB = Documents.Add 'Create new document. It becomes active MsgBox ActiveDocument oDocA.Activate 'make oDocA active MsgBox ActiveDocument oDocB.Activate 'make oDocB active MsgBox ActiveDocument oDocB.Close wdDoNotSaveChanges 'close the active document MsgBox ActiveDocument 'remaining open document becomes active. End Sub "Richard" <Richard(a)discussions.microsoft.com> wrote in message news:CCC22189-D3B0-4CF3-AF59-96546AEDEE9A(a)microsoft.com... > Hi > > I have a form.doc (A) which I need to e-mail to 3rd parties without the > code > to reduce file size. > > Code has been written to copy the text from the form to a new document > (B), > which I then need to save to enable it to be e-mailed via Outlook. > > The original document (A) is still the activeDocument, but to save the new > one (B), (B) needs to be the activeDocument for the code: > > ActiveDocument.Save > > to work. > > So, How do I make (B) the ActiveDocument (Which is not saved) & later > make > (A) the activeDocument to perform further tasks? > > Templates (.dot) are deliberately not being used as references get lost > when > files are moved in a big organisation. > > All contributions gratefully received. > > Thanks - Richard > -- > Richard
From: Richard on 31 Mar 2010 10:00 Hi Many thanks for help. Original question answered & all working. If one wants to then delete the new document (oDocB), how would you go about that? -- Richard "Greg Maxey" wrote: > Sub ScratchMaco() > Dim oDocA As Word.Document > Dim oDocB As Word.Document > Set oDocA = ActiveDocument 'Set the active document > Set oDocB = Documents.Add 'Create new document. It becomes active > MsgBox ActiveDocument > oDocA.Activate 'make oDocA active > MsgBox ActiveDocument > oDocB.Activate 'make oDocB active > MsgBox ActiveDocument > oDocB.Close wdDoNotSaveChanges 'close the active document > MsgBox ActiveDocument 'remaining open document becomes active. > End Sub > > > "Richard" <Richard(a)discussions.microsoft.com> wrote in message > news:CCC22189-D3B0-4CF3-AF59-96546AEDEE9A(a)microsoft.com... > > Hi > > > > I have a form.doc (A) which I need to e-mail to 3rd parties without the > > code > > to reduce file size. > > > > Code has been written to copy the text from the form to a new document > > (B), > > which I then need to save to enable it to be e-mailed via Outlook. > > > > The original document (A) is still the activeDocument, but to save the new > > one (B), (B) needs to be the activeDocument for the code: > > > > ActiveDocument.Save > > > > to work. > > > > So, How do I make (B) the ActiveDocument (Which is not saved) & later > > make > > (A) the activeDocument to perform further tasks? > > > > Templates (.dot) are deliberately not being used as references get lost > > when > > files are moved in a big organisation. > > > > All contributions gratefully received. > > > > Thanks - Richard > > -- > > Richard > > > . >
From: DaveLett on 31 Mar 2010 10:56 Hi Richard, I think you're looking for something like the following: Dim oDocA As Document Dim oDocB As Document Set oDocA = ActiveDocument Set oDocB = Documents.Add Then, you can just call each document object as needed. Such as the following: oDocB.Paragraphs(1).Range.text = oDocA.Paragraphs(4).Range.text oDocB.Save '''or SaveAs, depending on what you need. HTH, Dave "Richard" wrote: > Hi > > I have a form.doc (A) which I need to e-mail to 3rd parties without the code > to reduce file size. > > Code has been written to copy the text from the form to a new document (B), > which I then need to save to enable it to be e-mailed via Outlook. > > The original document (A) is still the activeDocument, but to save the new > one (B), (B) needs to be the activeDocument for the code: > > ActiveDocument.Save > > to work. > > So, How do I make (B) the ActiveDocument (Which is not saved) & later make > (A) the activeDocument to perform further tasks? > > Templates (.dot) are deliberately not being used as references get lost when > files are moved in a big organisation. > > All contributions gratefully received. > > Thanks - Richard > -- > Richard
|
Next
|
Last
Pages: 1 2 Prev: Deleting a specific field code in Footers Next: Character code for Enter Key |