directormac
Occasional Presence
- Local time
- Today, 17:25
- Joined
- Oct 24, 2001
- Messages
- 259
Hey Gang!
I've searched the archives but haven't found this one yet, and the MS KB was entirely unhelpful. I've created a tool to simplify and automate a lot of advance tasks for a touring stage production. In the interest of max flexibility for the end users, several of these tasks revolve around template MS Word documents (these folks have no interest in learning to edit reports--or, for that matter, Word bookmarks--they want to use their existing stock document files). No problem, I open up their stock docs, find and replace the agreed-upon markers with the correct values, save off the modified documents in the correct folder, then e-mail them or print them or whatever the occasion calls for.
BUT
I'm doing something wrong somewhere, because I get an error the SECOND time I do any kind of work in Word: "The remote server machine does not exist or is unavailable." Seems like I must be missing something in cleaning up after myself, because the first time I touch Word in a given session, everything's great. If I close my db (but not Access) and open again, it behaves nicely for one more call--then the same error again.
This has to be something simple, but I haven't found it yet. I found this thread which is tantalizingly close but centers around the use of ActiveDocument.Name which I don't use. Is the use of ANY ActiveDocument property or method suspect? Do I need to replace all such calls?
Relevant code below--any suggestions?
--Stumped Mac
I've searched the archives but haven't found this one yet, and the MS KB was entirely unhelpful. I've created a tool to simplify and automate a lot of advance tasks for a touring stage production. In the interest of max flexibility for the end users, several of these tasks revolve around template MS Word documents (these folks have no interest in learning to edit reports--or, for that matter, Word bookmarks--they want to use their existing stock document files). No problem, I open up their stock docs, find and replace the agreed-upon markers with the correct values, save off the modified documents in the correct folder, then e-mail them or print them or whatever the occasion calls for.
BUT
I'm doing something wrong somewhere, because I get an error the SECOND time I do any kind of work in Word: "The remote server machine does not exist or is unavailable." Seems like I must be missing something in cleaning up after myself, because the first time I touch Word in a given session, everything's great. If I close my db (but not Access) and open again, it behaves nicely for one more call--then the same error again.
This has to be something simple, but I haven't found it yet. I found this thread which is tantalizingly close but centers around the use of ActiveDocument.Name which I don't use. Is the use of ANY ActiveDocument property or method suspect? Do I need to replace all such calls?
Relevant code below--any suggestions?
--Stumped Mac
Code:
Public Function SetupBooking() As String
[COLOR=Gray]<SNIP documentation, other declarations...>[/COLOR]
' for dealing with the new .doc file...
Dim strPath As String
Dim strFileName As String
' for our work in MS Word...
Dim WordApp As New Word.Application
Dim WordReplace As Word.Dialog
[COLOR=Gray]<SNIP steps one and two...>[/COLOR]
' ***** STEP THREE: Create a template press schedule for the booking...
[COLOR=Gray]<SNIP setting up path & file name of template, other init stuff...>[/COLOR]
' Intialize the MS Word Application object:
Set WordApp = CreateObject("Word.Application")
With WordApp
[COLOR=Gray]<SNIP application visible or not based on Access user's prefs...>[/COLOR]
' Open the document.
.Documents.Open (strPath & strFileName)
' Do a global search and replace for each of the "variables" inserted...
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "{{BookingCity}}"
.Replacement.Text = GetCurrentVenueInfo("City")
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
[COLOR=Gray]<SNIP other replacements...>[/COLOR]
[COLOR=Green][B]' Note: I'm going to create a table of standard markers
' and replacements and just loop through them, but there
' are other fish to fry first...[/B][/COLOR]
End With
[COLOR=Gray]<SNIP set up path & file name of new customized version to save...>[/COLOR]
' And call Word's save routine:
.ActiveDocument.SaveAs strPath & strFileName
' We're done in Word, so close it up...
' Close the current document:
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' Quit the application:
.Quit
' Since we're done with Word, we can close the WITH bracket:
End With
' Last step: release the object resources:
Set WordApp = Nothing
Set WordReplace = Nothing
[COLOR=Gray]<SNIP step four and the rest of this function, which doesn't hit Word again>[/COLOR]