The following will add the found date to the end of the fourth line of the
Primary header story (for the first page header you need to change t
(wdPrimaryHeaderStory) to (wdFirstPageHeaderStory), but note you will get an
error if the firstpage header has been defined.
Dim rng2 As Range
Dim rng4 As Range
Dim sFound As String
Set rng2 =
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Paragraphs(2).Range
Set rng4 =
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Paragraphs(4).Range
rng4.End = rng4.End - 1
rng2.Select
With Selection.Find
Do While .Execute(findText:="[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4}", _
MatchWildcards:=True) = True
sFound = Selection.Text
Loop
End With
rng4.Text = rng4 & Chr(32) & sFound
With ActiveWindow
.View = wdPrintView
.View.SeekView = wdSeekMainDocument
.View = wdPrintView
End With
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
I've generated the following to find the date text. I still some
help to insert the desired text just before the end of the fourth
paragraph in the header.
Sub FindDateTextThenInsertText()
'
'code uses snippets from code posted by Greg Maxey, Graham Major,
'Helmut Weber and others.
Dim rngStory As Range
Dim sFound As String
Set rngStory = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
With rngStory.find
.Text = "<[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4}>"
.MatchWildcards = True
.Wrap = wdFindStop
If .Execute Then
sFound = rngStory.Text
End If
End With
'need something here to insert text based on sFound in just before
the end 'of paragraph 4 in wdPrimaryHeaderStory
End Sub
Thanks,
Raul
Raul said:
I need to search the wdFirstPageHeaderStory and find the date text
in the second paragraph and then enter some text (determined by the
date) at the end of the fourth paragraph.
The date text is in the format "mm/dd/yy" or "m/d/yy".
Can anyone help me get started?
Thanks in advance,
Raul