Search and replace involving a field

B

Bonsai Bill

I make extensive use of inserting fields for figures, tables and equations as
well as cross referencing in book chapters using simple macros. With
equations the publisher wants referenced equations formatted without
parentheses. When inserting cross referencing I add "Equation" and remove
"(".

However, whenever fields are updated the "(" comes back. I tried various
modified versions of search and replace found on this newsgroup but I can't
figure way to have VBA find the "(" and remove it without removing the entire
field. Because chapters are work in progress I don't want to clear the fields
yet.

Does someone have a tip on how to make the search and replace work where it
removes only the "(" in the field? I use Word XP.

Thanks for your input!
 
D

Doug Robbins - Word MVP

Where do the parentheses come from?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bonsai Bill

Hi Doug,

Thanks for your response.

The left parenthesis is inserted in the the field because I added it as a
caption label. I tried using a blank label which Word doesn't like. Looking
back, I probably should have selected Equation caption label and then
stripped off text and add the parentheses.

Is there an easy way of stripping out the "(" in the field? If not I might
be forced to modify the macros and then go back through written chapters.
Groan. However, I am only 1/3 through book.

Thanks for any suggestions you have!
 
D

Doug Robbins - Word MVP

Try adding the following formatting switch to the field:

\# 0

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bonsai Bill

Hi Doug,

Thanks for your response. I am sorry but you are beyond my knowledge level.

BTW, I was wrong in how I add the equations. I use AutoText to insert the
equation number into a two column table as suggested on this site. I then use
InsertCrossReference ReferenceType:="Equation"... for cross referencing.
MSWord adds a "(" and I strip it out. I don't see from Help any way to add
formatting switches.

If I can add the format switch when inserting the cross-reference it sounds
like that would resolve all problems. However, I just don't know how to do it.

Thanks for your input.
 
D

Doug Robbins - Word MVP

If you press Alt+F9, you will see something like

{ REF _Ref219083909 \h }

Modify it to

{ REF _Ref219083909 \# 0 \h }

then press Alt+F9 to toggle off the display of the field codes.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bonsai Bill

Hi Doug,

I played with field codes. When using the macro the update adds the "(" and
field code doesn't have \h switch. Adding this or \#0 gives an error on
updating.

If I have a file without the macro and do the insert and cross-reference
there is no "(" upon updating and \h is present. I wonder if the AutoText is
causing the problem?

Anyhow, I was found an inelegant solution to problem. Thanks for your
suggestions! I learned more about field switches. I am disappointed that Help
didn't have the #0 switch.
 
B

bonmac

I have a similar problem in that I want to remove a colon ":" from the end of
the cross-reference and so I tried this answer just for the heck of it and it
did not work. I have also tried all the Ref field switches - like \n, \r, \w
and \t - but none of them worked either. Does anyone know the answer as to
how to remove the colon ":" in a cross-reference? - thanks - Bonnie
 
B

Bonsai Bill

Hi bonmac,

I have been away from forum for some time. Hopefully, you have resolved your
problem by now. If not, please read on.

I too failed to find the proper switch to help. Below is a routine that
finds "Equation (" and then deletes the (. If you have variable length fields
you can search forward until you find the ":" and then do backspace.

I hope this helps,
Bonsai Bill

Sub RemoveParen()

Selection.Find.ClearFormatting
With Selection.Find
..Text = "Equation"
..Replacement.Text = "Equation"
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With

Do While Selection.Find.Execute
Selection.MoveStart Unit:=wdCharacter, Count:=10 'go to (
Selection.TypeBackspace
Loop

End Sub ' RemoveParen
 

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