How do I tie a document object to the one I just opened. The document I end
up saving is blank. Somehow I need to get the one I just opened into the
document object that is being saved.


Dim MyWord As Word.Application
Dim WordDoc As Word.Document

Set MyWord = New Word.Application
With MyWord
.Documents.Open ("c:\test.doc")
Set WordDoc = MyWord.Documents.Add
WordDoc.SaveAs "c:\test1.doc"
DoEvents

Set MyWord = Nothing
Set WordDoc = Nothing

Re: Problems with document and application object by Tony

Tony
Sun Oct 01 11:57:09 CDT 2006

Set a variable to the document you open and then use that handle to
manipulate the correct document.

eg
Dim DocOpened As Word.Document
Set DocOpened = .Documents.Open("c:\test.doc")

you can then do
DocOpened.Save etc.

Cheers
TonyS.

News.Microsoft.com wrote:
> How do I tie a document object to the one I just opened. The document I end
> up saving is blank. Somehow I need to get the one I just opened into the
> document object that is being saved.
>
>
> Dim MyWord As Word.Application
> Dim WordDoc As Word.Document
>
> Set MyWord = New Word.Application
> With MyWord
> .Documents.Open ("c:\test.doc")
> Set WordDoc = MyWord.Documents.Add
> WordDoc.SaveAs "c:\test1.doc"
> DoEvents
>
> Set MyWord = Nothing
> Set WordDoc = Nothing