Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel to Word automation

Status
Not open for further replies.

misubud

IS-IT--Management
May 29, 2002
25
NZ
Am getting unusual error when trying to open and save word documents from excel vba.
The following code works fine on the first run. Opens doc, saves as a new file, with values placed in bookmarks.

The problem is that even if I delete the saved file, i.e. 1234.doc, I receive the following error when I next try to run the macro (that is, if i comment the error handling out!) a second time.

Any assistance appreciated.


error msg :"Run-time error '-2147023174(800706ba)'
Automation Error
The RPC server is unavailable"

code;

Public Sub test2()
On Error GoTo errorHandler
Dim myDoc As Word.Document
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
wdApp.Documents.Open FileName:="d:\Abc.doc", ReadOnly:=True
Set myDoc = wdApp.ActiveDocument
myDoc.Bookmarks("test1").Range = "11111"
myDoc.Bookmarks("test2").Range = "2222"
ActiveDocument.SaveAs FileName:=("d:\1123.doc")

errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing

End Sub
 
Instead of this:
ActiveDocument.SaveAs FileName:=("d:\1123.doc")
Try this:
myDoc.SaveAs FileName:=("d:\1123.doc")
wdApp.Quit

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks Heaps PHV.
Did the trick!

Must have been tying itself in knots with the "activedocument.saveas".

Once again, THANKS!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top