Find and Replace Symbol with Nothing?

F

FJ

Hi, I have what is probably be a very simple problem. I want to find all
instances of certain symbols, for instance, symbol 183 (the round bullet
character), and replace them with nothing. I found an excellent macro at the
following site http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm
that will find and replace one symbol with another, but I can’t seem to edit
it to make it replace a symbol with nothing. I know I am probably missing
something very obvious here, but I’m a real VBA beginner so I really don’t
know what I’m doing. Does anyone know how to edit this macro or can suggest
anyone another macro that would do this?

Thanks in advance for any information.
 
J

Jay Freedman

Hi, I have what is probably be a very simple problem. I want to find all
instances of certain symbols, for instance, symbol 183 (the round bullet
character), and replace them with nothing. I found an excellent macro at the
following site http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm
that will find and replace one symbol with another, but I can’t seem to edit
it to make it replace a symbol with nothing. I know I am probably missing
something very obvious here, but I’m a real VBA beginner so I really don’t
know what I’m doing. Does anyone know how to edit this macro or can suggest
anyone another macro that would do this?

Thanks in advance for any information.

The ReplaceAllSymbols macro in the article you quoted wasn't really designed for
that, but it can be modified as follows:

- Replace the two lines

Sub ReplaceAllSymbols(FindChar As String, FindFont As String, _
ReplaceChar As String, ReplaceFont As String)

with the line

Sub DeleteAllSymbols(FindChar As String, FindFont As String)

- Replace the three lines

'Insert the replacement symbol where the found symbol was
Selection.InsertSymbol Font:=ReplaceFont, _
CharacterNumber:=ReplaceChar, Unicode:=True

with the lines

'Delete the found symbol
Selection.Delete

- The macro that calls this modified macro also needs to be changed by omitting
the ReplaceChar and ReplaceFont parameters; for example:

Sub DeleteAllDeltaSymbols()
'Call the main "DeleteAllSymbols" macro (below),
'and tell it which character code and font to search for
Call DeleteAllSymbols(FindChar:= ChrW(-3996), FindFont:= "Symbol")
End Sub
 
F

FJ

Hi, actually, I think I should have posted the code from the link I provided.
Here it is:

Sub ReplaceAllDeltaSymbolsWithBetaSymbols()
'Call the main "ReplaceAllSymbols" macro (below),
'and tell it which character code and font to search for, and which to
replace with
Call ReplaceAllSymbols(FindChar:= ChrW(-3996), FindFont:= "Symbol", _
ReplaceChar:=-3998, ReplaceFont:="Symbol")
End Sub


--------------------------------------------------------------------------------

Sub ReplaceAllSymbols(FindChar As String, FindFont As String, _
ReplaceChar As String, ReplaceFont As String)

Dim FoundFont As String, OriginalRange As Range, strFound As Boolean
Application.ScreenUpdating = False

Set OriginalRange = Selection.Range
'start at beginning of document
ActiveDocument.Range(0, 0).Select

strFound = False
With Selection.Find
.ClearFormatting
.Text = FindChar
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute
'keep searching until nothing found
If Dialogs(wdDialogInsertSymbol).Font = FindFont Then
'Insert the replacement symbol where the found symbol was
Selection.InsertSymbol Font:=ReplaceFont, _
CharacterNumber:=ReplaceChar, Unicode:=True
Else
Selection.Collapse wdCollapseEnd
End If
Loop

End With

OriginalRange.Select

Set OriginalRange = Nothing
Application.ScreenUpdating = True

End Sub
 
F

FJ

Hi, Jay, thank you so much! :) I used your modifications and it worked
perfectly. :)

Thanks again! :)
 
F

FJ

Hi, Graham, thanks for your reply. I tried using ^0183 in the Find and
Replace box but I couldn't get it to work. I tried it with the "Use
wildcards" option checked and unchecked but I couldn't get it to work either
way. Is there something else I have to do? I don't do a lot of
advanced/wildcard find and replaces so there might be something obvious I'm
missing.

Thanks in advance for any information.
 
G

Graham Mayor

You don't need wildcards checked, but I misunderstood which character you
were actually searching for. Use Jay's method.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

FJ

Hi, Graham, thanks for your reply. I will use Jay's method, but I'll keep
your tip in mind for use with other characters.

Thanks again. :)
 

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