MS Word macro: Using varible for Windows("filename 123.doc").Activate

Is it possible to use a true variable for Windows("").Activate?

Currently  I have Windows("filename 123.doc").Activate

however this macro needs to be used on several files.

I need the Windows("").Activate to accodomate so that I don't have to change the name for each file.

Better to show use more of the code that you are using.

However, you can definitely use something like

Dim mydoc as Document

Set mydoc = Documents.Open("Path\Filename")

mydoc.Activate

In the above situation, no need to use Windows()

Of course, when you open a document, it is by default the active document, but your code could be

Dim Doc1 as Document, Doc2 as Document

Set Doc1 = Documents.Open("Path\Filename")

Set Doc2 = Documents.Add

in which case Doc2 would be the active document.  So if you wanted to make Doc1 the active document, you would use

Doc1.Activate

In many situations however, it is not necessary to activate the document, particularly if you use the .Range object rather than the .Selection object.

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated February 22, 2023 Views 353 Applies to: