View Single Post
 
Old 10-20-2022, 06:48 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

In my experience with floating shapes in the headers, VBA seems to think all the shapes are in every section even though the user interface shows a graphic only in one sections header. This can be further complicated when some headers may have 'Link to Previous' turned on.

So I have no faith at all in being able to use VBA to determine which shape you are referring to via the section number.

If you have some shapes in your document headers, try this macro to see the way VBA keeps track of these shapes.
Code:
Sub TestHeaderFloaters()
  Dim aH As HeaderFooter, aShp As shape, aSect As Section
  
  Debug.Print ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.Count
  
  For Each aSect In ActiveDocument.Sections
    For Each aH In aSect.Headers
      For Each aShp In aH.Shapes
        Debug.Print aSect.Index, aH.Index, aShp.Anchor.Information(wdActiveEndSectionNumber), aShp.AlternativeText
      Next aShp
    Next aH
  Next aSect
  
End Sub
When I've tried to deal with this problem (years ago), I ended up using the AlternativeText to 'tag' the shapes I put into the header. Then I iterated through the shapes to find the one that had the Alt Text I wanted.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote