Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-28-2022, 08:58 PM
oyster oyster is offline how to use word vba to read header, mixed with text and shape, on last page of very section? Windows 10 how to use word vba to read header, mixed with text and shape, on last page of very section? Office 2013
Novice
how to use word vba to read header, mixed with text and shape, on last page of very section?
 
Join Date: Jun 2022
Posts: 1
oyster is on a distinguished road
Default how to use word vba to read header, mixed with text and shape, on last page of very section?

In fact, I have asked this on how to use word vba to read header, mixed with text and shape, on last page of very section? - Stack Overflow but there is no solution yet.


The situation is, sometimes I have to check some papers. The check items include checking whether the header has proper literal information. macropod supplies a solution for text in header on how to use word vba to read header's text on last page? - Stack Overflow .

However, I meet doc which mixes text and shape in the header, and the useful information is actually in shape. I made a simplified version mix_txt_shape_in_header.docx and put it on GitHub - retsyo/study_vba_doc

For this doc, what I expected is to extract all displayed text( so it should be read from both text and text_in_shape) on last page in every section, and prompt something like

Code:
Index page i of i  
Main part page 2 of 32
English is not my native language. I hope I have make it clear by using above doc and expected output.

After study macropod's code, I think if I can select the shape in the header, I can read the information. But soon I meet questions


  • how to select the shape
I record a vba code while I operate on shape in header, and find that shape's name is used in the vba, for example
Code:
ActiveDocument.Shapes("TextBox 1").Select
obviously, it is not applicable because I can't know shape's name in advance.

  • for the reason I stated above, I can't figure out how to get the text of shape, which is on the last page of every section. Here is what I get as far as I can

Code:
Sub read()     
    NumSections = ActiveDocument.Sections.Count     
    For idxsec = 1 To NumSections         
        With ActiveDocument.Sections(idxsec).Headers(wdHeaderFooterPrimary)
             numShape = .Shapes.Count
             For idxShape = 1 To numShape
                 txt = "section " & idxsec & ", shape " & idxShape & ": "
                 txt = txt & .Shapes(idxShape).TextFrame.TextRange.Text
                 Debug.Print txt
             Next
         End With
         Debug.Print "====="
     Next
End Sub



However it says
Code:
section 1, shape 4:  
section 1, shape 4: page i of  i 
section 1, shape 4:                          <-- why this shape is in section 1 ?
section 1, shape 4: page 1 of  32            <-- why this shape is in section 1 ?
===== 

section 2, shape 4:                          <-- why this shape is in section 2 ?
section 2, shape 4: page i of  i             <-- why this shape is in section 2 ?
section 2, shape 4:  
section 2, shape 4: page 1 of  32 
=====
it is clear that
Code:
 Sections(idxsec).Headers(wdHeaderFooterPrimary).Shapes
does not find shape in the section only, on the other hand, it finds all shape in the doc

  • to simulate what human eyes read from header, I have to judge which one, text or text_in_shape, should be placed first.

3.1 for the text
there is no something like
Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages, wdHeaderFooterOddPages, or wdHeaderFooterPrimary).Range.Width
3.2 for the shape


Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Shapes(2).Width
produces

Code:
 68.2
which seems to be reasonable, however

Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1).left
returns
Quote:
-999996


as what Shrotter told me, it is WdShapePosition, then how to get its real x position


Any help? Thanks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't change Page Number in header in new section Very Terry Word 2 10-15-2018 07:25 AM
how to use word vba to read header, mixed with text and shape, on last page of very section? Amend text shape in header with VBA Welshgasman Word VBA 9 09-22-2016 01:16 AM
how to use word vba to read header, mixed with text and shape, on last page of very section? begin each section with page 1 in header PLUS continuous page numbering in footer onemorecupofcoffee Word 18 09-04-2013 04:31 PM
how to use word vba to read header, mixed with text and shape, on last page of very section? Page 2 Section Header not same as Page 1 Same Section Lakey Word 4 08-07-2012 08:42 PM
how to use word vba to read header, mixed with text and shape, on last page of very section? Help! Section Page Break Not Working - Need new Header and Footers dkgolfer16 Word 2 05-23-2012 11:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:09 AM.


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