Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Speed Up Replacement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mamue - 28 Jan 2008 08:59 GMT
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
Graham Mayor - 28 Jan 2008 10:08 GMT
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).

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi there,
>
[quoted text clipped - 34 lines]
>
> Matthias
mamue - 28 Jan 2008 13:45 GMT
> 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
[quoted text clipped - 56 lines]
>
> > Matthias

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.
Graham Mayor - 28 Jan 2008 13:59 GMT
Point taken about the header/footer, but the autotext field would still work
for the text box and its content.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

>> If you are using autotext to populate a document and that text is
>> subject to change, then you would probably be better inserting an
[quoted text clipped - 65 lines]
> to put the textbox to the header&footer section since the users need
> to modify the default content afterwards, on each page separately.
mamue - 28 Jan 2008 15:44 GMT
> Point taken about the header/footer, but the autotext field would still work
> for the text box and its content.
[quoted text clipped - 76 lines]
> > to put the textbox to the header&footer section since the users need
> > to modify the default content afterwards, on each page separately.

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
Graham Mayor - 29 Jan 2008 08:46 GMT
> Hmm, maybe i didn't understand exactly how i could use autotext fields
> here. as far as i understood autotext fields are placeholders for
[quoted text clipped - 5 lines]
> - 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.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.