|
-
Feb 6th, 2023, 06:19 AM
#8
Thread Starter
Junior Member
Re: Word automation started giving errors - Now have to close and re-create Word obje
 Originally Posted by Elroy
I just scanned your code, but one thing I did see is the use of ActiveDocument. Personally, when doing this, I always create object variables for each opened document and use those variables for manipulating the documents. Let me find an example:
Code:
Set wrd = WordApp ' Basically just: Set wrd = CreateObject("Word.Application")
wrd.Visible = False
Set doc = WordAddDoc(wrd, sTemplateSpec)
WordSetTemplate doc ' I can talk more about this if you like.
'
InWordReplaceAllOccurencesInBody doc, "[Hospital]", HospitalName ' Just to make things easier.
WordSaveAs doc, sFileSpec ' Basically just: doc.SaveAs sFileSpec
wrd.Quit False ' THIS is very important!!!
' And then I just let the wrd variable fall out of scope, as I'm done with it.
Would you be kind enough to show me the code for how you deal with find and replace when the document is set as an object?
Also under .activedocument I was able to return a variable if the text was found or not by using TextFound = .selection.find.found but I can't seem to use this with the Doc object.
Many thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|