A
Andy Bowles
Version: Word 2000 SR-1
I have some text that I need to use within an If field. The text may
contain double quotes, and may also contain other fields.
Because the If field treats a double quote as delimiting an argument, I want
to replace any double quotes with a Symbol field representing the quote.
However, if a double quote is within a field, I want to leave it unchanged.
I can do the first part like this:
Private Sub Replace_Quotes(sel as Word.Selection)
While Find_Text(sel, """")
sel.Fields.Add sel.Range, wdFieldSymbol, "34", False
Wend
End Sub
Private Function Find_Text(sel As Word.Selection, search_text As String)
With sel.Find
.ClearAllFuzzyOptions
.ClearFormatting
.Forward = True
.MatchWholeWord = False
.MatchWildcards = False
.Text = search_text
.Wrap = wdFindStop
Find_Text = .Execute
End With
End Function
This works, but that if my selection contains a field like this:
{ TIME \@ "dd MMMM yyyy" }
the quotes inside the field also get replaced with the Symbol field.
So, is there any way to determine whether sel.Range relates to something
that's inside a field?
If there isn't, I suppose I could do it by recording each field's definition
before I start, and then restoring each field to it's original state. Is
there a better way?
Thanks.
Andy Bowles
I have some text that I need to use within an If field. The text may
contain double quotes, and may also contain other fields.
Because the If field treats a double quote as delimiting an argument, I want
to replace any double quotes with a Symbol field representing the quote.
However, if a double quote is within a field, I want to leave it unchanged.
I can do the first part like this:
Private Sub Replace_Quotes(sel as Word.Selection)
While Find_Text(sel, """")
sel.Fields.Add sel.Range, wdFieldSymbol, "34", False
Wend
End Sub
Private Function Find_Text(sel As Word.Selection, search_text As String)
With sel.Find
.ClearAllFuzzyOptions
.ClearFormatting
.Forward = True
.MatchWholeWord = False
.MatchWildcards = False
.Text = search_text
.Wrap = wdFindStop
Find_Text = .Execute
End With
End Function
This works, but that if my selection contains a field like this:
{ TIME \@ "dd MMMM yyyy" }
the quotes inside the field also get replaced with the Symbol field.
So, is there any way to determine whether sel.Range relates to something
that's inside a field?
If there isn't, I suppose I could do it by recording each field's definition
before I start, and then restoring each field to it's original state. Is
there a better way?
Thanks.
Andy Bowles