Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 23 Sep 2008 11:42:12 -0700,    group: microsoft.public.word.vba.general        back       


Update text in document range without affecting fields   
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
date: Tue, 23 Sep 2008 11:42:12 -0700   author:   Wes from Scottsdale

Re: Update text in document range without affecting fields   
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 :-)
date: Wed, 24 Sep 2008 17:23:37 +0200   author:   Cindy M.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us