Searching thru Header

T

Tyson Ackland

Can someone point me in the right direction please? I wish to locate the
header in a Word doc and then copy the second line of text I find in the
header so I can use it elsewhre in the code.

TIA!

TyBreaker
 
H

Helmut Weber

Hi Tyson,
maybe this helps.
Sub HeadTest()
Dim i As Integer
Dim p As Integer
With ActiveDocument
p = .Paragraphs.Count
For i = 1 To p
If .Paragraphs(i).OutlineLevel < 10 Then
.Paragraphs(i).Range.Select
If CountLines() > 1 Then
.Paragraphs(i).Range.Select
With Selection
.HomeKey
.MoveDown
.ExtendMode = True
.EndKey unit:=wdLine
MsgBox Selection.Text
' the second line of a headers
' if there is a second one
' further things to do here, up to you
.ExtendMode = False
End If
End If
Next
End With
End Sub
Public Function CountLines() As Integer
' 10 = wdFirstCharacterLineNumber
Dim z1 As Integer
Dim z2 As Integer
With Selection
z1 = .Information(10)
.EndKey
z2 = .Information(10)
CountLines = z2 - z1 + 1
End With
End Function
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
H

Helmut Weber

Didn't read your second posting.
If you need only the first header,
exit the for ... next loop if found
Greetings from Bavaria, Germany
Helmut Weber
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top