Searching for a graphic in a header/footer

S

Sol Apache

Hello

I cannot find anything in Mac VisualBasic for Word to show how I can find an
anchored graphic (a logo) and to switch its visibility on or off for
printing.

If I put the logo in a text box inline a paragraph with a unique style I can
get VB to change it to hidden text, but I cannot change it back to visible!
VB cannot find the text box, which is in the header.

Can anyone help me with the VB for either:

1. finding an anchored standalone graphic in the header (once found I change
its visibility by changing its transparency?).

Can I assign a number or name to the graphic in case the letter writer
decides to put another graphic in the main part of the letter?

or

2. finding a textbox in the header with a graphic inline with hidden text of
a specific style.

Thanks for any help.
 
D

Doug Robbins - Word MVP

I am not sure about doing it on a Mac, but in windows versions, you can turn
off the printing of graphics by unchecking the "Drawing objects" box under
Tools>Options>Print. To use VBA to do that, you would use

Options.PrintDrawingObjects = False

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sol Apache

Thanks for this. But won¹t this stop all graphics in a document from being
printed? I just want the logo to not print. It¹s unlikely that a user will
put extra graphics in the letter/document, but there will always be an
exception (as you well know).
 
M

Martin Sägesser

Hi

In my documents there are shapes and inlineshapes, and I use this
procedure to change them - perhaps you can change it for your VB.

hth, Martin


'---
Sub LogoChange()
' change visibility of graphics in header

Dim ishp As InlineShape

On Error GoTo LogoChange_Err

' Bildschirm wird nicht aktualisiert
Application.ScreenUpdating = False

' temporäre Textmarke an aktueller Stelle gesetzt
ActiveDocument.Bookmarks.Add Name:="temp"

' Gehe zu Seite 1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"

' Erste Fusszeile wird geöffnet
ActiveWindow.ActivePane.View.Type = wdPageView
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader

' Alle Grafiken aus oder eingeblendet
ActiveDocument.Sections(1).Headers
(wdHeaderFooterPrimary).Shapes.SelectAll

With Selection.ShapeRange.PictureFormat
If .Brightness = 0.5 Then
.Brightness = 1#
.Contrast = 0#
pubbLogos = False
Else
.Brightness = 0.5
.Contrast = 0.5
pubbLogos = True
End If
End With

For Each ishp In ActiveDocument.Sections(1).Headers
(wdHeaderFooterFirstPage).Range.InlineShapes
If ishp.PictureFormat.Brightness = 0.5 Then
ishp.PictureFormat.Brightness = 1#
ishp.PictureFormat.Contrast = 0#
Else
ishp.PictureFormat.Brightness = 0.5
ishp.PictureFormat.Contrast = 0.5
End If
Next ishp

For Each ishp In ActiveDocument.Sections(1).Headers
(wdHeaderFooterPrimary).Range.InlineShapes
If ishp.PictureFormat.Brightness = 0.5 Then
ishp.PictureFormat.Brightness = 1#
ishp.PictureFormat.Contrast = 0#
Else
ishp.PictureFormat.Brightness = 0.5
ishp.PictureFormat.Contrast = 0.5
End If
Next ishp

' Sprung zur temporären Textmarke, Löschen der Textmarke
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete

' Bildschirmaktualisierung einschalten
Application.ScreenRefresh
Application.ScreenUpdating = True
Exit Sub
' wenn kein Fehler wird Sub beendet

LogoChange_Exit:
Exit Sub

' Fehlerbehandlungsroutine
LogoChange_Err:

If ActiveWindow.ActivePane.View.Type <> wdPageView Then
ActiveWindow.ActivePane.View.Type = wdPageView

ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete

If bProtect Then
ActiveDocument.protect Password:="", Type:
=wdAllowOnlyFormFields, NoReset:=True
bProtect = False
End If

Application.ScreenRefresh
Application.ScreenUpdating = True
MsgBox "Das aktuelle Dokument enthält keine Grafiken in der
Kopfzeile", vbInformation, TEXT_MSGBOX

Resume LogoChange_Exit

End Sub
'---
 
S

Sol Apache

Hello

Thanks for this. I’ll get someone to translate the German then I can test it
out.

Sol
 
M

Martin Sägesser

Hi Sol

I was hoping the commands were enough to understand it... translation
see below!

Martin


Hello

Thanks for this. I’ll get someone to translate the German then I can test it
out.

Sol

MsgBox "No Picture found in Header", vbInformation, TEXT_MSGBOX
 

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