Re: Reference Field Error!
- From: "Jay Freedman" <jay.freedman@xxxxxxxxxxx>
- Date: Tue, 17 Feb 2009 16:51:16 -0500
I wouldn't consider the necessary code to be simpler than the fields, but
very well...
Insert a bookmark starting at the left side of the first comma and ending at
the right side of the second comma. I named the bookmark "RefAttention", but
if you choose a different name you need only change the value assigned to
the constant BkmNm in the macro.
Sub DeleteErroredFields()
Const BkmNm = "RefAttention"
Dim bCodesVisible As Boolean
bCodesVisible = ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = False
With ActiveDocument.Bookmarks
If .Exists(BkmNm) Then
.Item(BkmNm).Range.Fields.Update
If InStr(.Item(BkmNm).Range.Text, "Error!") Then
.Item(BkmNm).Range.Delete
End If
End If
End With
ActiveWindow.View.ShowFieldCodes = bCodesVisible
End Sub
singeredel wrote:
Thanks. I appreciate your input!
I have played with those complex field codes in the past and it is
just too confusing and I could never get it to work because I do need
to have the punctuation deleted also. I just preferred to have it in
the code to hopefully make it simpler.
singeredel wrote:
I have the following sentence and reference fields in a template:
Thank you, { REF AttentionTitle\* CharFormat } {REF
AttentionLineLast \* Charformat }, for allowing me to take part in
the care of your patient.
After running the program to create the document using the template,
sometimes the fields pertaining to these references are blank and
therefore it leaves the error message "Error! Reference Source not
found. Error! Reference Source not found" in the reference fields,
as follows:
"Thank you, { Error! Reference source not found. } { Error!
Reference source note found }, for allowing me to take part..."
I would like to know how to write code to just delete these messages
if these errors are found so that the text reads:
"Thank you for allowing me..."
Thanks!
You don't need macro code. What you do need is a somewhat complex
field code that displays a result only when it isn't the error
message. The first field becomes
{ IF { REF AttentionTitle } <> "Error! Reference source not found."
{ QUOTE ", { REF AttentionTitle \* CharFormat }" } }
and the second field becomes
{ IF { REF AttentionLineLast } <> "Error! Reference source not
found." { QUOTE "{ REF AttentionLineLast \*
Charformat }, " } }
Notice the placement of the commas inside the QUOTE field rather
than in the text outside the field -- if the fields don't display
anything, you don't want the commas either. You may have to play
with this a bit to get the placement of spaces to be correct.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
.
- References:
- Reference Field Error!
- From: singeredel
- Re: Reference Field Error!
- From: Jay Freedman
- Re: Reference Field Error!
- From: singeredel
- Reference Field Error!
- Prev by Date: Hilight row in a table
- Next by Date: Re: Applying styles through VBA
- Previous by thread: Re: Reference Field Error!
- Next by thread: Macro to select multiple sentences
- Index(es):
Relevant Pages
|