Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error controlling Word from Excel

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Error controlling Word from Excel

Hi,

Following a link I found elsewhere, I actually managed to solve my own
problem. I'm posting the solution here in the hopes that it might help
someone else who encounters the same problem.

Using this Microsoft Knowledge Base post
(http://support.microsoft.com/kb/189618/EN-US/), I figured out that I was not
referring to my Word object properly, as I had initialized it as WordApp, but
was attempting to control it via the Word object alone.

Old, incorrect version:
Word.ActiveDocument.Bookmarks("Name").Select

New, correct version:
WordApp.ActiveDocument.Bookmarks("Name").Select

It works like a treat now. I still don't understand why it semi-worked
before, but I guess that's not as important.

Thanks to anyone who looked at this with an eye toward helping out.

Best wishes...

....Jay

"Jason" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling MS Word from VBA Excel danp_db Excel Programming 2 October 31st 05 04:04 PM
Error while controlling Word from Excel JFamilo[_11_] Excel Programming 4 August 15th 05 01:58 AM
Controlling Word from Excel Paul Haywood Excel Programming 3 June 30th 04 11:13 AM
Controlling Word from Excel tonesmcbutt Excel Programming 1 January 7th 04 09:21 PM


All times are GMT +1. The time now is 12:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"