Update text in document range without affecting fields

  • Thread starter Wes from Scottsdale
  • Start date
W

Wes from Scottsdale

I'm working with Footers, searching for one string value to replace it with
another. If the footer has fields in it and I assign ...Footers(#).Range =
Replace(stuff, ...Footers(#).Range), the fields are converted to static text.
How can I keep the actual value of the Range intact to write it to another
Range or a variable, updating some text while maintaining the dynamic fields?

Here is the relevant line of code :
ActiveDocument.Sections(s).Footers(h).Range =
Replace(ActiveDocument.Sections(s).Footers(h).Range, OrigDocID, NewVersion)

Thanks,
Wes
 
C

Cindy M.

Hi =?Utf-8?B?V2VzIGZyb20gU2NvdHRzZGFsZQ==?=,
I'm working with Footers, searching for one string value to replace it with
another. If the footer has fields in it and I assign ...Footers(#).Range =
Replace(stuff, ...Footers(#).Range), the fields are converted to static text.
How can I keep the actual value of the Range intact to write it to another
Range or a variable, updating some text while maintaining the dynamic fields?
There's no way you can run a string-based (pure text) function on a range and
retain non-text. The Replace function is part of Visual Basic, not the Word
object model. And you're not really working with the Range object, but it's Text
property. The code VBA is really working with, behind the scenes is:

ActiveDocument.Sections(s).Footers(h).Range.TEXT =
Replace(ActiveDocument.Sections(s).Footers(h).Range.TEXT, OrigDocID, NewVersion)

The Text property delivers and receives a "plain string" without formatting.

If you want to retain formatting you're probably better off using Range.Find
with Replace.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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