Toggle hide/show graphics with a macro button

D

Deejay

I wish to create a button containing a macro which would toggle a graphic in
the header to switch it to show or hide as required. Is this possible? If so,
how?

Many thanks!

I am using Word 2007 with Vista.
 
J

Jean-Guy Marcil

Deejay was telling us:
Deejay nous racontait que :
I wish to create a button containing a macro which would toggle a
graphic in the header to switch it to show or hide as required. Is
this possible? If so, how?

Many thanks!

I am using Word 2007 with Vista.

It depends on the actual set up (Which header, which section, etc.).

But basically, all you need is something like this:

With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1)
.Visible = Not .Visible
End With

Or, once you create the shape, you can use the following code to name it
(Run the second sub once - NameShape).
This way, if shapes are added, you do not have to worry about .Shapes(1)
pointing to the right shape or not:

'_______________________________________
Option Explicit

Private Const strShape As String = "MyLogo"
'_______________________________________
Sub ToggleShapeVis()

With
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(strShape)
.Visible = Not .Visible
End With

End Sub
'_______________________________________

'_______________________________________
Sub NameShape()

With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1)
.Name = strShape
End With

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top