Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Manipulating graphics within macros (2003 SP1)

    Hi all

    My clients occasionally ask me to create Word template versions of their stationery (usually opening page and follower) with the graphics embedded in the header.

    In the past, I've been able to impress the heck out of them with a toolbar button or menu command that toggles the display of the graphics without altering vertical positioning of the document body, so that they can use preprinted stationery if required (it's easier than it sounds - just use a macro to select each graphic and turn its brightness up to 100% - or back to default, whichever they want).

    Since switching to Word 2003, I've noticed that it no longer permits graphics to be selected and manipulated if I am recording a macro - it doesn't matter whether they are in the header / footer or document body. While recording a macro, I've also tried to select a graphic by hitting F5 and "+" - but this just takes me out of header / footer view. If I try it in the document body, it just generates an audible warning.

    My preference is to position the graphics in-line rather than floating, but I'll compromise on this if necessary (I don't seem to be getting the desired result with either option.)

    And if that wasn't enough of a challenge, my current client operates Word 97, 2000 and XP (no, they haven't taken the plunge on 2003 yet).

    Once again, I'd be enormously grateful if someone who knows more than me about this stuff could suggest a workaround for this limitation that will work on all of these versions of Word. (I have, of course, trawled previous postings, but not found anything on this topic.) I am sure some of the Lounge Legends know how to get around this.

    Thanks in advance

    Neil

  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating header graphics with macros (97 & up)

    If you have named the shape, you can use this macro.:

    <pre>Sub LogoOnOff(strName As String, blnVisible As Boolean)
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'or wdSeekCurrentPageFooter
    With Selection.HeaderFooter.Shapes(strName)
    If blnVisible = True Then
    .Visible = msoTrue
    Else
    .Visible = msoFalse
    End If
    End With
    End Sub
    </pre>


    If you haven't given the shape a name you can use the index number. Change the relevant lines into
    Sub LogoOnOff(iIndex As Integer, blnVisible As Boolean)
    and
    With Selection.HeaderFooter.Shapes(iIndex)

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

    Re: Manipulating graphics within macros (2003 SP1)

    I don't have word 2003, but perhaps you can use or adapt the following code:

    Sub ToggleShapes()
    Dim shp As Shape
    For Each shp In ActiveDocument.Sections(1).Headers(1).Shapes
    shp.PictureFormat.Brightness = 1.5 - shp.PictureFormat.Brightness
    Next shp
    End Sub

    It'll toggle the brightness of shapes between 0.5 (50%) and 1 (100%).

  4. #4
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating header graphics with macros (97 &

    Jan hi

    That sounded like a plan - but I'm embarrassed to say that I'm not familiar with "naming" objects, so I'll have to research this a little.

    I tried pasting the code (with the indexing changes you proposed) as a new macro and it won't even display in the list of available macros. I like to think that I'm not a complete amateur with this stuff, but I've never seen that happen before!

    Thanks for your help

    Neil

  5. #5
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating graphics within macros (2003 SP1)

    Hans

    Many thanks for your prompt reply. I tried this & the graphic briefly blinked on and off - but nothing else. I tried starting with brightness=0 and 100% to see if I could figure out what was going on, but after running the macro, the value is unchanged.

    But the code does appear to allow me access the graphics in the header through a macro, so that's a step forward!

    Thanks again

    Neil

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

    Re: Manipulating graphics within macros (2003 SP1)

    Are the graphics inline shapes or floating shapes?

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating header graphics with macros (97 &

    Don't know why the macro doesn't appear in the list of macros.
    Just curious: why are you manipulating the brightnes of the shape instead of the Visible property?

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

    Re: Manipulating header graphics with macros (97 &

    A macro is a Sub without any arguments. Your procedure takes two arguments, therefore it is not listed in the Tools | Macro | Macros dialog. It has to be called from other code (for example from a macro), or from the Immediate window.

  9. #9
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating header graphics with macros (97 &

    Oops, I should have known... <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Thanks Hans

  10. #10
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating graphics within macros (2003 SP1)

    Hans

    I'd prefer inline, but they can be floating if that will expedite a solution.

    neil

  11. #11
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating header graphics with macros (97 &

    Jan

    I got Hans' tip earlier about calling your macro from another macro, so I'll give that a try.

    As for brightness vs Visible, I wasn't aware of the Visible property - is that available from the format picture options, or only through a macro? If it's the latter, the reason would be that I tend to create almost all of my macros by recording and and tweaking them if necessary with limited skills. But I am always delighted to learn from experts!

    Any suggestions most welcome!

    Thanks again

    Neil

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

    Re: Manipulating graphics within macros (2003 SP1)

    Try this macro:

    Sub ToggleGraphhics()
    Dim hf As HeaderFooter
    Dim oShape As InlineShape
    Dim sect As Section
    ' Hide what we're doing
    Application.ScreenUpdating = False
    ' Switch to header/footer view
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _
    = wdMasterView Then
    ActiveWindow.ActivePane.View.Type = wdPageView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ' Loop through sections
    For Each sect In ActiveDocument.Sections
    ' Loop through headers
    For Each hf In sect.Headers
    If Not hf.LinkToPrevious And hf.Exists Then
    ' select range
    hf.Range.Select
    ' Toggle shape
    For Each oShape In Selection.InlineShapes
    oShape.PictureFormat.Brightness = 1.5 - oShape.PictureFormat.Brightness
    Next oShape
    End If
    Next hf
    Next sect
    ' Back to main doc
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    ' Show result
    Application.ScreenUpdating = True
    End Sub

  13. #13
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating graphics within macros (2003 SP1)

    Hans

    That's amazing - it works brilliantly! It even works on a second page header that has been defined, even when there is only one page in the document.

    At the risk of stretching a friendship (I always seem to do this on the 2-3 occasions a year that I post queries here), can I ask your advice on making this apply at the same time to a graphic that will be in the footer?

    I'm sure I could simply copy the body of the macro & alter it to change "header" references to "footer" - or is there a substantially more efficient way of doing it?

    I've noticed that this is definitely oriented towards in-line graphics - so I may set myself a project of figuring out how to adapt this to floating pix also.

    Once again - thanks very much indeed (to you and Jan) for taking the time to come up with solutions for me - it is very greatly appreciated!

    Kindest regards

    Neil

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

    Re: Manipulating graphics within macros (2003 SP1)

    You don't have to duplicate the entire macro, you only need to duplicate the loop

    For Each hf In sect.Headers
    ...
    Next hf

    and change the copy to

    For Each hf In sect.Footers
    ...
    Next hf

  15. #15
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Manipulating graphics within macros (2003 SP1)

    Hans - you may be encouraged to know that I just figured that out by myself!

    And one very, very last question (for real - it's almost 11pm here): can you suggest a way to detect the current view (e.g. normal, print) etc at the beginning of the macro & then set it back to that at the end? Some of my client's users have extremely limited skills and even changing view would spook them.

    Thanks a million for all your help

    neil

Page 1 of 2 12 LastLast

Posting Permissions

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