K
Kerri
Hi,
I am currently using Word 2003. I am using story ranges for the
headers and footers. I am having a few problems.
If there is a Page number in a text box in the Footer and you use any
of the collapse options it will collapse in the text box and therfore
insert text in the textbox. I want it to collapse to the beginning of
the Footer text not in the text box. I was using the Collapse options
so I could then bookmark the new text inserted in that range. I
realize you can use InsertBefore but that won't let me then make the
text I just inserted in to a bookmarked range...or will it?
Goals:
1. Go through the Footer stories and insert text for all stories.
2. Insert BEFORE all other text.
3. Bookmark the text just inserted with a unique name for each section
4. If Bookmark already exist then just replace that text with new text
Problem:
1. If I have 2 sections it will run the macro 2x and insert text 2x
into the footer.
2. If there is nothing in the footer it will error... I don't have
the code below but I will usually have it open the storyrange and
insert a space so I can put text in it.
3. If there is a TEXT BOX in the footer it will insert it in that
textbox and not in the footer.
4. If there is existing text in the footer, I want it to tab it over
or move to next line after I insert my text. This sounds easier than
it's been.
Thank you for your help.
Kerri
Here is my CODE:.
Sub FooterText()
Dim pFooter As Word.Range
Dim pIndex As Long
For pIndex = 1 To 4
On Error Resume Next
Set pFooter = ActiveDocument.StoryRanges(Choose(pIndex,
wdEvenPagesFooterStory, wdFootnotesStory, wdPrimaryFooterStory,
wdFirstPageFooterStory)) 'wdFirstPageFooterStory,
On Error GoTo 0
Do Until pFooter Is Nothing
:
strMyText = "_TEST_"
' pFooter.Text = "blah blah blah" 'This replaced all existing
text
Dim strBKEnd, strBKMKName As String
If pFooter.Text <> "" Then
' pFooter.InsertBefore strMyText
pFooter.Collapse wdCollapseStart '*keeps it from
bookmarking the entire footer
pFooter.InsertBefore strMyText
SecIndex = pFooter.Sections.Count
Select Case pFooter.StoryType
Case wdFirstPageFooterStory
strBKEnd = "_First"
Case wdEvenPagesFooterStory
strBKEnd = "Even"
Case Else
strBKEnd = ""
End Select
strBKMKName = "BKMK_" & SecIndex & strBKEnd
pFooter.Bookmarks.Add (strBKMKName)
End If
:
Set pFooter = pFooter.NextStoryRange
Loop
Next
End Sub
I am currently using Word 2003. I am using story ranges for the
headers and footers. I am having a few problems.
If there is a Page number in a text box in the Footer and you use any
of the collapse options it will collapse in the text box and therfore
insert text in the textbox. I want it to collapse to the beginning of
the Footer text not in the text box. I was using the Collapse options
so I could then bookmark the new text inserted in that range. I
realize you can use InsertBefore but that won't let me then make the
text I just inserted in to a bookmarked range...or will it?
Goals:
1. Go through the Footer stories and insert text for all stories.
2. Insert BEFORE all other text.
3. Bookmark the text just inserted with a unique name for each section
4. If Bookmark already exist then just replace that text with new text
Problem:
1. If I have 2 sections it will run the macro 2x and insert text 2x
into the footer.
2. If there is nothing in the footer it will error... I don't have
the code below but I will usually have it open the storyrange and
insert a space so I can put text in it.
3. If there is a TEXT BOX in the footer it will insert it in that
textbox and not in the footer.
4. If there is existing text in the footer, I want it to tab it over
or move to next line after I insert my text. This sounds easier than
it's been.
Thank you for your help.
Kerri
Here is my CODE:.
Sub FooterText()
Dim pFooter As Word.Range
Dim pIndex As Long
For pIndex = 1 To 4
On Error Resume Next
Set pFooter = ActiveDocument.StoryRanges(Choose(pIndex,
wdEvenPagesFooterStory, wdFootnotesStory, wdPrimaryFooterStory,
wdFirstPageFooterStory)) 'wdFirstPageFooterStory,
On Error GoTo 0
Do Until pFooter Is Nothing
:
strMyText = "_TEST_"
' pFooter.Text = "blah blah blah" 'This replaced all existing
text
Dim strBKEnd, strBKMKName As String
If pFooter.Text <> "" Then
' pFooter.InsertBefore strMyText
pFooter.Collapse wdCollapseStart '*keeps it from
bookmarking the entire footer
pFooter.InsertBefore strMyText
SecIndex = pFooter.Sections.Count
Select Case pFooter.StoryType
Case wdFirstPageFooterStory
strBKEnd = "_First"
Case wdEvenPagesFooterStory
strBKEnd = "Even"
Case Else
strBKEnd = ""
End Select
strBKMKName = "BKMK_" & SecIndex & strBKEnd
pFooter.Bookmarks.Add (strBKMKName)
End If
:
Set pFooter = pFooter.NextStoryRange
Loop
Next
End Sub