Speed Up Replacement

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
 
G

Graham Mayor

If you are using autotext to populate a document and that text is subject to
change, then you would probably be better inserting an autotext field to
insert both the text box and its content (because the text boxes are not in
the text layer of the document fields do not always respond as you might
imagine). It is then fairly straightforward to revise the autotext entry and
update the fields, which being in the text layer are easily updated without
recourse to addressing each story range..

If the text box is to appear on every page then it should be in the document
headers (assuming the same content) which will place it there. Changing
content can often be addressed with Styleref fields (preferably in a frame
or table cell and not in a text box - as both frames and tables are in the
text layer of the document).

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mamue

If you are using autotext to populate a document and that text is subject to
change, then you would probably be better inserting an autotext field to
insert both the text box and its content (because the text boxes are not in
the text layer of the document fields do not always respond as you might
imagine). It is then fairly straightforward to revise the autotext entry and
update the fields, which being in the text layer are easily updated without
recourse to addressing each story range..

If the text box is to appear on every page then it should be in the document
headers (assuming the same content) which will place it there. Changing
content can often be addressed with Styleref fields (preferably in a frame
or table cell and not in a text box - as both frames and tables are in the
text layer of the document).

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Thanks Graham for the very fast reply. Your approach is interesting,
i've never heard from autotext fields before. but i don't think that
this is applicable to my need. the autotext i put on each page is a
textbox with a table in it. the content of the table needs to be
replaced by a macro (and the corresponding user action). i don't want
to put the textbox to the header&footer section since the users need
to modify the default content afterwards, on each page separately.
 
G

Graham Mayor

Point taken about the header/footer, but the autotext field would still work
for the text box and its content.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mamue

Point taken about the header/footer, but the autotext field would still work
for the text box and its content.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hmm, maybe i didn't understand exactly how i could use autotext fields
here. as far as i understood autotext fields are placeholders for
autotext entries. i put them to in my document and after refreshing
the corresponding content is filled. but what about the replacement of
that content. do i have to do that before? for example:
- inserting autotext
- replace it and
- store new autotext temporary
- fill content with new autotext using fields
 
G

Graham Mayor

mamue said:
Hmm, maybe i didn't understand exactly how i could use autotext fields
here. as far as i understood autotext fields are placeholders for
autotext entries. i put them to in my document and after refreshing
the corresponding content is filled. but what about the replacement of
that content. do i have to do that before? for example:
- inserting autotext
- replace it and
- store new autotext temporary
- fill content with new autotext using fields

The autotext field places the autotext entry with the correct information so
that you don't have to use a macro to change it. It makes more sense to
insert the correct information in the first place. Autotext (or includetext)
allows you to have the correct information inserted. If the users want to
change that inserted table later there is nothing stopping them. Autotext
and Includetext ensure that it is relatively simple to maintain the inserted
information.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top