automating Find & Replace with a " (ascii(34) character)

B

Brian McCullough

Hello all!

I am trying to automate the Find and Replace functionality in Word XP. My
VBA code is below and i am having problems when I try to use a " (double
quote) in the Replacement.Text value. Word tries to convert it to an open
quote character, rather than just a double quote character, i think.

Set m_objWord = New Word.Application
Set objDoc = m_objWord.Documents.Add(Template:="MyTemplate.dot",
NewTemplate:=False)
Set objRange = objDoc.Content
'objField below is a custom object that stores Name/Value pair...

With objRange.Find
.Text = "<<" & objField.Key & ">>"
.Replacement.Text = cstr(objField.Value) 'the value i am trying
to use as replacement text is: Ë88534"Î
.Forward = True
.Wrap = 1 'wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

.Execute Replace:=2 'wdReplaceAll
End With

Any help/input is greatly appreciated!!!

Thanks!

Brian
 
W

Word Heretic

G'day Brian,

No it is not.

Type Alt+F11 (VBE) Ctrl+G (Immediate Window)

Enter:

Selection.Find.Text=""" 'that's three double quotes in a row

Flip back to word, Alt+F11, select into the document if necc and press
Ctrl+F. Your text field contains a double quote.


Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: Steve at wordheretic.com


Brian McCullough was spinning this yarn:
 
K

Klaus Linke

Hi Brian,

Your problem is
Options.AutoFormatAsYouTypeReplaceQuotes = True

Set it to False before you do the replacement, and back to True afterwards.

With the setting True, Word will try to turn straight quotes into smart
quotes in the replacement.

Klaus
 

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