Quote Originally Posted by Elroy View Post
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.