J
Jason
Hi,
I wrote a simple (I thought) macro to populate a Word document from
Excel (both are Office 2003). I seem to be doing something wrong at
the end of the macro when I kill off the Word object, because the
macro appears to work fine the first time I invoke it and then fails
the next time with the error message "Run-time error '462': The remote
server machine does not exist or is unavailable." I then have to go
into the Task Manager and manually kill the Winword process. When I
do this, I can then run the macro again--once--before getting the
error again the second time I run it. It's frustrating, and I'd
really appreciate it if anyone can lend their wisdom and help me make
it fully functional.
Here's the applicable code (repetitive code in the middle has been
removed for clarity):
Sub Populate_Report()
Dim WordApp As New Word.Application
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open ("C:\Report.doc")
Word.ActiveDocument.Bookmarks("Name").Select 'NOTE: This is the
indicated line when the macro breaks
Word.Selection.TypeText NameValue
....
Word.ActiveDocument.SaveAs Filename:="C:\" & ReportName & ".doc"
WordApp.Quit
Set WordApp = Nothing
My thanks to anyone who can help me.
Best wishes...
....Jay
I wrote a simple (I thought) macro to populate a Word document from
Excel (both are Office 2003). I seem to be doing something wrong at
the end of the macro when I kill off the Word object, because the
macro appears to work fine the first time I invoke it and then fails
the next time with the error message "Run-time error '462': The remote
server machine does not exist or is unavailable." I then have to go
into the Task Manager and manually kill the Winword process. When I
do this, I can then run the macro again--once--before getting the
error again the second time I run it. It's frustrating, and I'd
really appreciate it if anyone can lend their wisdom and help me make
it fully functional.
Here's the applicable code (repetitive code in the middle has been
removed for clarity):
Sub Populate_Report()
Dim WordApp As New Word.Application
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open ("C:\Report.doc")
Word.ActiveDocument.Bookmarks("Name").Select 'NOTE: This is the
indicated line when the macro breaks
Word.Selection.TypeText NameValue
....
Word.ActiveDocument.SaveAs Filename:="C:\" & ReportName & ".doc"
WordApp.Quit
Set WordApp = Nothing
My thanks to anyone who can help me.
Best wishes...
....Jay