Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Location
    Chicago, Illinois, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call A Macro (VBA/Word 2002)

    I would like a macro to check the paper size of the document (is it letter or A4) and then run another macro in the template for that size document. I wrote the following code and it works great if the document is letter size but a document sized as A4 is running the letter macro. I can't figure out why. Any help is appreciated.

    Public Sub Main()

    If ActiveDocument.PageSetup.PaperSize = wdPaperLetter Then
    Application.Run MacroName:="Normal.LetterheadLogoLtr.Main"
    Else
    Application.Run MacroName:="Normal.LetterheadLogoA4.Main"
    EndIf

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Call A Macro (VBA/Word 2002)

    Try the following:
    - Open or create a document with A4 paper size.
    - Activate the Visual Basic Editor (Alt+F11).
    - Activate the Immediate window (Ctrl+G).
    - Type
    <code>
    ? ActiveDocument.PageSetup.PaperSize
    </code>
    - Press Enter.
    - Which number is returned? It should be 7 (=wdPaperA4)

  3. #3
    New Lounger
    Join Date
    Feb 2004
    Location
    Chicago, Illinois, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Call A Macro (VBA/Word 2002)

    Thanks for the reply. It does return a 7. This is why I am stumped on why my code is not working. The logo macro works fine if I run it separately, it just doesn't work when I first try to check the paper size and call it from the first macro. I've called macros from within another macro before, but for some reason this one just does not work and I wasn't sure if I was doing something wrong.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Call A Macro (VBA/Word 2002)

    That's strange - I tested your code (substituting two macros that I have in my Normal.dot template), and it worked correctly for both Letter and A4 size.

    Are you sure that the document you're testing is the active document when the code is run?

    What happens if you change the code to

    Public Sub Main()
    If ActiveDocument.PageSetup.PaperSize = wdPaperLetter Then
    Call Normal.LetterheadLogoLtr.Main
    Else
    Call Normal.LetterheadLogoA4.Main
    EndIf
    End Sub

Posting Permissions

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