I'm hoping a VB/VBA expert can help me out. Consider the following:
The user opens a document in Word 2003, and within the Normal.dot AutoOpen
macro, we look at current document, and if it has been opened by clicking on a link on a webpage, and meets certain other application specific criteria, close the streamed 'copy' and open the source document (found on a shared drive we can assume the user has access to):
Documents.Open origDoc
Documents(ActiveDocument.FullName).Close SaveChanges:=wdDoNotSaveChanges
Documents(origDoc).Activate
With ActiveDocument
''# Do work
End With
My thought was that I needed to call Activate
to ensure that the original document was the ActiveDocument
, but I'm getting a 4160 'Bad file name' error on the .Activate
call. If I comment out the call to .Activate
, it appears that ActiveDocument
is set to the origDoc document, even if there were other documents already opened (I'm not really sure how the Documents Collection is managed, and how Word determines what next ActiveDocument
would be if you programatically close the current ActiveDocument)
So, does calling .Open
on a document explicitly set the Document to be the ActiveDocument
? Also, does calling .Activate
on the already active document cause an error?
I haven't really been able to find much documentation about this, so thanks in advance for any suggestions and insight!