Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 10-20-2022, 06:48 PM
Guessed's Avatar
Guessed Guessed is offline Macro is manipulating item in wrong section even though variable watch says it should be right Windows 10 Macro is manipulating item in wrong section even though variable watch says it should be right 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Footnote numbering wrong after section break peterbav Word 1 03-17-2020 11:18 PM
Macro is manipulating item in wrong section even though variable watch says it should be right How do I make a checkbox or dropdown item reference data in that specific section of the data array? dhare Excel Programming 2 02-24-2016 12:36 PM
Macro is manipulating item in wrong section even though variable watch says it should be right Copying data related to one item to worksheet with many instances of the same item nmp13 Excel 3 02-06-2016 02:13 AM
Multilevel Numbering wrong after Section Break Kay Wood Word 2 01-16-2013 08:44 AM
Help with VBA macro - Variable input sc30317 Excel Programming 0 08-31-2011 01:00 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft