Hi All,
Does anyone know is it possible to select all data between two
header ? I can find header # 1 by running followed code:
Selection.Find.ClearFormatting
Selection.GoTo what:=wdGoToHeading, which:=wdGoToAbsolute, Count:=1,
Name:=""
Thanks!
Assuming you mean between paragaphs formatted with the same paragraph
style eg "Heading 1"
The code below will do it.
Note: I assume by header you mean some sort of heading in the text. I
further assume the heading is formatted using a paragraph style called
"Heading 1". In the word context header can also refer to the
paragraph style called "Header" but usually refers to the text that
appears at the top of each page as distinct from the the "Footer" also
a defalut word style but also meaning the bit that appears at the
bottom of every page, ad defined using "View Header/Footer".
I hope this is more helpfule to get you thinking.
Cheers!
TonyS.
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
'moves the selection off the found heading 1 style
'towards the end of the document
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
' will extend the selection from here to wherever
' the next find takes us
Selection.Extend
'find the neaxt heading
Selection.Find.Execute
'move the end of the selection to before the start of this
selection/heading style
' Selection.HomeKey Unit:=wdLine, Extend:=True
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=True
Selection.HomeKey Unit:=wdLine, Extend:=True
Selection.ExtendMode = False
X = Selection.Text
'set up to before the previous find in case we want to recurse
this operation
Selection.Collapse wdCollapseEnd