|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 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
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.
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
3.1 for the text there is no something like Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages, wdHeaderFooterOddPages, or wdHeaderFooterPrimary).Range.Width Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Shapes(2).Width Code:
68.2 Code:
? ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1).left |
|
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 |
Amend text shape in header with VBA | Welshgasman | Word VBA | 9 | 09-22-2016 01:16 AM |
begin each section with page 1 in header PLUS continuous page numbering in footer | onemorecupofcoffee | Word | 18 | 09-04-2013 04:31 PM |
Page 2 Section Header not same as Page 1 Same Section | Lakey | Word | 4 | 08-07-2012 08:42 PM |
Help! Section Page Break Not Working - Need new Header and Footers | dkgolfer16 | Word | 2 | 05-23-2012 11:02 AM |