PDA

View Full Version : Change text in textbox within footer



mdmackillop
10-30-2009, 09:34 AM
In the attached workbook, the Section Break and text is added by code. Same as Previous is removed from the Section 2 footer. I want to change "Carried to Collection Page" to "Carried to Summary", but I can't find a way to access the Textbox. Any inspiration?

RolfJ
10-30-2009, 12:16 PM
Looking at your document I still see the 'Same as Previous' tag by the Section 2 Footer, but I can't seem to find the 'Carried To Collection Page' tag...

Tinbendr
10-30-2009, 05:12 PM
Put some unique text in the box.

Sub AccessToTextbox()
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
MsgBox oShp.TextFrame.TextRange.Text
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next

End Sub
Pilfered from here (http://word.mvps.org/faQs/Customization/ReplaceAnywhere.htm).

mdmackillop
10-31-2009, 05:44 AM
That looks promising. I'll give it a try.

fumei
11-03-2009, 09:40 AM
Why use a textbox?

mdmackillop
11-04-2009, 04:13 AM
Hi Gerry,
The Textbox was the simplest solution at the time.

Tinbendr,
Your solution works fine. As I have to change the Section 2 footer only, this version lets me identify and change the correct location.

Sub AccessToTextbox()
Dim rngStory, oShp, Cnt As Long
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then

If Mid(oShp.TextFrame.TextRange.Text, 11, 10) = "Collection" And Cnt = 1 Then
oShp.TextFrame.TextRange.Text = "Amount to Summary"
Exit Sub
Else
If Mid(oShp.TextFrame.TextRange.Text, 11, 10) = "Collection" Then
Cnt = 1
End If
End If

End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub

fumei
11-05-2009, 10:45 AM
A textbox is the simplest? How can that be? Plain text is the simplest. The very fact you are forced to use code like
oShp.TextFrame.HasText
and StoryRanges, makes it NOT simple.

Looking at the document, I fail to see any reason whatsoever to use a textbox.