Consulting

Results 1 to 3 of 3

Thread: Switch Documents - to Make ActiveDocument For Macro

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Switch Documents - to Make ActiveDocument For Macro

    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
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,337
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    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

    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
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •