Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Is there anyway of hiding/showing a picture (using VBA) added to the header of the first page? BTW: The picture/image takes the full height/width of the page. This document could have other images as part of the normal user information.

    Basically, I need to hide the backdrop/picture when the document is printed but show it when the document is PDFed.

    EDIT: Just noticed an option under Tools|Options|Print -> Background colours and images. But, setting to unsetting this has no effect to the backdrop/watermark added to the first page. :-(
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use code such as

    Code:
    Sub ToggleShape()
      With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1)
    	.Visible = Not .Visible
      End With
    End Sub
    You'll have to edit the macro: the number 1 in Shapes(1) may vary; you'll have to find out which number to use by experimenting.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    When you are in the visual basic editor you can use the immediate window to set the Name of the shape with code like
    ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Shapes(1).Name = "MyShape"
    Then you can reference this shape as
    ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Shapes("MyShape")
    in the code that toggles the visible property.

    This may be more robust when future changes are made to the document.

  4. #4
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787931' date='07-Aug-2009 16:21']You can use code such as

    Code:
    Sub ToggleShape()
      With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1)
    	.Visible = Not .Visible
      End With
    End Sub
    You'll have to edit the macro: the number 1 in Shapes(1) may vary; you'll have to find out which number to use by experimenting.[/quote]

    Stuart: Like the idea of naming a shape. Didn't know we can do that - you learn something new everyday.

    Thanks Hans. Your macro works fine except (there is alway an except) whenever I try to run the macro second and subsequent times it comes up with a message 'Code execution has been interrupted'! Doesn't matter how long I wait between running the macro - 5, 10, 15 minutes etc. Any idea why and how to fix it? Also, it always stops at the start of the macro.

    EDIT 10:28: Strange! I found this by accident. If I open or switch to another window (not word) then the next toggle works fine. Switch another window, come back to word, click toggle and it works fine. Click toggle & one gets the interrupted error. No help on the Microsoft site :-(.
    Thanks.
    Robie

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I can't explain that. I can run the macro several times in succession without a problem.

  6. #6
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='788234' date='10-Aug-2009 10:13']I can't explain that. I can run the macro several times in succession without a problem.[/quote]

    The it must be to do with some differences in settings. I even rebooted my PC just to keep Word happy but alas no difference.

    Microsoft Knowledgebase is of no use & neither is google - no one seems to have an answer.

    I guess, I will just have to let my users know that if you get a message 'Code execution has been interrupted' - just click Continue. Not very nice but seems to be the only solution at the moment.
    Thanks.
    Robie

Posting Permissions

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