Starting Word from Access - 2nd time fails
When starting up Word from a form in Access, I do this:
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordRange As Word.Range
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
Set wordDoc = wordApp.Documents.Open(etikettenTemplate)
' fill in some bookmarks in the word doc
Set wordApp = Nothing
Set wordDoc = Nothing
Set wordRange = Nothing
The problem is: this runs fine the first time the code runs. The second time I get a runtime error 462: The remote server computer doesn't exist or is not available.
The trouble is, I can't c开发者_运维问答ontrol the whole cycle, as the user may need to edit the word doc before closing. Am I doing something wrong? Thanks for any suggestion
Sorry, have been able to solve the problem myself.
The error was that I was accessing the bookmarks of the doc through
ActiveDocument.Bookmarks(mybookmark).Range
instead of the previously chosen wordDoc variable
By changing all occurences of ActiveDocument with wordDoc the problem vanished.
Thanks to all anyway
精彩评论