PDA

View Full Version : [SOLVED:] Switch Documents - to Make ActiveDocument For Macro



dj44
10-21-2016, 05:04 PM
Hi folks,

How is everyone doing,:)

Now I thought this was a easy thing to do as it worked in one macro but then it stopped and ive been in a conundrum.

Lets say im in Doc1 - and my macro is in Doc1,
I simply want to make Doc2 my active document



Sub SwitchWindowsMacro()

'Documents("Doc2.docx").Activate
'Document("Doc2.docx").Activate
'Dim oDoc = ActiveDocument

Windows("Doc2").Activate
Selection.Font.Color = 7662449
Selection.Font.Size = 22
End Sub

thats a simpke example

How can i activate and make the Doc2 my active document so the macro can continue to do it's said proposed job?

thank you for your coding expertise on this matter

gmaxey
10-21-2016, 05:46 PM
Sub SwitchWindowsMacro()
Dim oDoc As Document, oDoc1 As Document, oDoc2 As Document
Set oDoc1 = ThisDocument 'The document containing the code.
If Documents.Count > 1 Then
If oDoc1 = Documents(1) Then
Set oDoc2 = Documents(2)
Else
Set oDoc2 = Documents(1)
End If
oDoc2.Activate
Selection.Font.Color = 7662449
Selection.Font.Size = 22
End If
End Sub

dj44
10-21-2016, 06:22 PM
Hello Greg,


Nice to see you , hope you are doing great!

I havent had time to come on forum as my macros have been keeping me busy :grinhalo:

Well who knew - the vba documentations showed it all together wrong

This is my first foray into swithcing documents and - it took me hours of trying and no document swithced in the end

Oh well thanks for the rescue - as always

thanks for always helping us newbs, Have a great weekend now Greg -


And folks too
:beerchug: