[word] problem with showing/hiding shapes

D

dwergkees

Got a strange problem:

A document has a corporate logo, which doesn't need to be printed on
the clients pc (as he has preprinted paper). The logo does need to be
printed other computers (when client for example mails a document).

My solution is as follows: intercept the print commands on clients pc,
hide the logo before printing, show it again when ready.

Code is on bottom of page. The strange problem is: When I open the
document and try to print, it doesn't work the first time, but it does
work the second. Both times the sub is called and processed with no
errors, as both times I get the messageBoxes(!). Also, it does work
directly when the VBA window is open.

Any ideas?

Code:

Sub FilePrint()
'To intercept File > Print and CTRL-P
toggleLogos

End Sub


Sub FilePrintDefault()
'To intercept the Standard toolbar button
toggleLogos True

End Sub


Sub toggleLogos(Optional toolbar As Boolean = False)

Dim logo As Shape, headerLogo As Shape

' fetch prenamed shapes
Set logo = Application.ActiveDocument.Shapes("Logo")
Set headerLogo =
Application.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrim­ary).Shapes("LogoHeader")


' Just to check if this sub is called properly
MsgBox logo.Name
MsgBox headerLogo.Name

' hide shapes
logo.Visible = msoFalse
headerLogo.Visible = msoFalse

' show print dialog or just spit it out
If toolbar Then
ActiveDocument.PrintOut
Else
Dialogs(wdDialogFilePrint).Show
End If

' show shapes
logo.Visible = msoTrue
headerLogo.Visible = msoTrue

End Sub
 

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