Delete Paragragh with specified text and style

K

Karen VM

I'm basically a recorder-type macro creator. I'm try to get a macro to find
text of a particular style containing a specified word and then delete the
whole paragraph, and keep searching for the next.
 
G

Graham Mayor

Something like

Dim oRng As Range
Dim i As Long
Dim sText As String
Dim sStyle As String
sText = InputBox("Enter word to find", "Delete Paragraph")
sStyle = InputBox("Enter style name", "Delete Paragraph")
For i = ActiveDocument.Paragraphs.Count To 1 Step -1
Set oRng = ActiveDocument.Paragraphs(i).Range
If oRng.Style = sStyle Then
If InStr(1, oRng, sText) Then
oRng.Delete
End If
End If
Next i


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Karen VM

It didn't work; I'm using Word 2003 if that helps. I'd also like to delete
the figure below the paragraph I want to delete.
 
G

Graham Mayor

It should work with Word 2003 if your original requirement was correctly
specified. Can you send me a sample document to the link on the home page of
my web site, with details of what *exactly* you wish to be removed.?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Karen VM

Unfortunately, I can't send you my document. I work for a pharmaceutical
company and the document is confidential. However, I did figure out how to
make it work. I used "find and replace" to get me to the figure caption and
then the internal bookmark for page and was able to delete exactly what I
wanted too. Thank you so much for taking the time to answer my question. This
site is wonderful!
 

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