2017-06-19 2 views
0

Je veux supprimer et ajouter une forme existante dans Word (en-tête et pied de page) avec un boutonsupprimer et ajouter des formes dans Word

Mais je ne peux pas choisir la forme pour modifier la propriété visible.

Comment est-ce que je peux faire ceci? Je ne peux pas comprendre le nom de la forme dans le mot

Merci pour votre aide!

Sub LogoChangeVisible() 
' 
' Removes and adds the logo from Header and Footer 
' 
' 
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 

Selection.HeaderFooter.Shapes("Picture from Header").Select 

If Selection.ShapeRange.Visible = msoTrue Then 
Selection.ShapeRange.Visible = msoFalse 
Selection.HeaderFooter.Shapes("Picture from Footer").Select 
Selection.ShapeRange.Visible = msoFalse 

ElseIf Selection.ShapeRange.Visible = msoFalse Then 
Selection.ShapeRange.Visible = msoTrue 
Selection.HeaderFooter.Shapes("Picture from Footer").Select 
Selection.ShapeRange.Visible = msoTrue 
End If 

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 

End Sub 

Répondre

0

Si vous ajoutez quelque chose comme ceci:

For Each s In Selection.HeaderFooter.Shapes 
    Debug.Print s.Name 
Next 

vous obtiendrez alors les noms dans votre fenêtre de débogage. Une autre approche consiste à ignorer les noms et passer par des numéros à la place:

Selection.HeaderFooter.Shapes(1)... 
+0

Il n'a trouvé aucune forme. Est-ce que ça compte comme une forme si c'est une image jpg? –

+0

Oui, ça compte comme une forme, mais ça peut aussi être une forme en ligne. Essayez ceci: Debug.Print ActiveDocument.Sections (1) .Headers (wdHeaderFooterPrimary) .Range.InlineShapes.Count – Sam