M
mamue
Hi there,
i try to find the best approach to replace text in text boxes. i
insert autotext in text boxes to every page in my document. afterwards
i need to replace that inserted default text with more specific data.
my approach was like this:
- insert autotext to every page
- loop through all StoryRanges
- loop through all Shapes in each Range
- replace the text in that Shape
here's the sample code:
-----------------------------
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
If rngStory.StoryType = wdMainTextStory Then
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
'Replacement
End If
Next
End If
End If
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothin
Next
-----------------------------
What are your best practices?
Is there maybe a way to replace the autotext "before" inserting it?
thanks for your help,
Matthias
i try to find the best approach to replace text in text boxes. i
insert autotext in text boxes to every page in my document. afterwards
i need to replace that inserted default text with more specific data.
my approach was like this:
- insert autotext to every page
- loop through all StoryRanges
- loop through all Shapes in each Range
- replace the text in that Shape
here's the sample code:
-----------------------------
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
If rngStory.StoryType = wdMainTextStory Then
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
'Replacement
End If
Next
End If
End If
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothin
Next
-----------------------------
What are your best practices?
Is there maybe a way to replace the autotext "before" inserting it?
thanks for your help,
Matthias