Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word - Where am I within Primary Header?

Status
Not open for further replies.

ikards

Technical User
Jun 16, 2000
9
US
I am replacing a name and date in the second-page header ("Primary Header" per Word) of a letter with the following code:
Set PriHdr = ActiveDocument.Sections(1). _
Headers(wdHeaderFooterPrimary).Range
With PriHdr.Find
.Text = "Name"
.Replacement.Text = sName
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
.Text = "Date"
.Replacement.Text = sDate
.Wrap = wdfindContinue
.Execute Replace:=wdReplaceAll
End With

This works fine except that it adds an extra Paragraph Mark after the replaced Date. I would like to delete the extra vbCr immediately after the date. But I don't know how to find out where I am within the header after the second (date) replacement. I tried:
Set PriHdr = PriHdr.Next(wdParagraph, 1)
but that got error msg. I'm really a newbie at VBA and am having a hard time always knowing how to tell where I am and how to get where I want to go... Any help would be appreciated. Thanks!
 
you may want to check that the variable sDate does not have the character vbCr in it.

if right$(sdate,1)=vbcr then
sdate=left$(sdate,len(sdate)-1)
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top