Macro to find and delete strikethrough

A

Abuelo

The macro seemed to work in the recording phase. I used "Find" and selected
"Strikethrough" under the "Formatting" button. But when I ran the macro it
just deleted the next character. In "Edit", the "With Selection.Find"
routine did not contain anything looking like "Strikethrough".
 
G

Greg Maxey

If you mean text strickened with the font attribute strikethrough then try
this:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "*"
.MatchWildcards = True
.Font.StrikeThrough = True
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End Sub
 
A

Abuelo

Thanks! That worked. I experimented around, using "ReplaceOne" insteadof
"ReplaceAll" (-- is there a way of going through a document doing strikeout
by strikeout instead of all of them? --), and using "Underline = True"
instead of "Strikeout = True" (-- is there a way of simply removing the
strikeout/underline but leaving the text? --).
 
A

Abuelo

Thanks, Jay. I read the article, and it was very helpful. I don't suppose
there's some well organized and consolidated reference for the command
structure of VBA, or what works with Macros. I'm not interested in being a
programmer (-- the last I did was with Pascal in the 90s --), but I need to
be able to make these Word macros work (and shouldn't have to be spoon fed in
this very helpful forum).
 
J

Jay Freedman

Well, what constitutes a "well organized and consolidated reference" is a
subjective judgment.

The built-in / online VBA help (also available from the MSDN site starting at
<http://msdn2.microsoft.com/en-us/library/aa272078(office.11).aspx> for
Word-specific topics and
<http://msdn2.microsoft.com/en-us/library/aa271312(office.11).aspx> for general
Office VBA) is comprehensive and reasonably well organized once you figure out
what the organization scheme is. The drawback is that with each release the
indexing has gotten worse, so you sometimes can't find topics you know exist.

There are several books about VBA. I don't use them, so I won't try to recommend
any.

The articles linked from http://word.mvps.org/FAQs/MacrosVBA/index.htm cover
some how-to topics and the sort of "doesn't work the way it's supposed to" that
you won't find in the official documentation. Another site to check is
http://www.vbaexpress.com/forum/ .

Thanks, Jay. I read the article, and it was very helpful. I don't suppose
there's some well organized and consolidated reference for the command
structure of VBA, or what works with Macros. I'm not interested in being a
programmer (-- the last I did was with Pascal in the 90s --), but I need to
be able to make these Word macros work (and shouldn't have to be spoon fed in
this very helpful forum).
--
Abuelo


Jay Freedman said:
The article http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm
discusses the bug in the macro recorder that makes it fail to record formatting
as part of searches, and how to fix them as Greg has done.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
-- Jay
 

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