PDA

View Full Version : Solved: Search for and delete all paragraphs beginning with '



Jinky Julie
06-23-2009, 07:34 AM
Hi again...

Another "easy" one that I just can't get to work...

I have a "large" report (20+ pages) and the software puts a bunch of garbage lines (by garbage I mean superfluous information).

Each line is preceded by the ' (apostrophe) character.

I wish to search the entire document, find each line (paragraph) beginning with the ' (apostrophe) and delete the entire line (paragraph).

I am sure it's a simple one for all the VBAExpress Experts...

As always... thanks for your patience and help...

Julie....

fumei
06-23-2009, 10:16 AM
Have you even tried recording a macro? Because you are correct...this is an easy one.

Jinky Julie
06-24-2009, 07:12 AM
Hi again...

YES!!! I have tried recording a macro... Unless I am doing something wrong, Word is finding all instances of ' not just the lines beginning with it... that is not what I want to do...

Find line (paragraph) with Character 1 (or 0) = '
Select entire line (paragraph)
Delete entire line (paragraph)
Repeat until no more

That's it...

joms
06-24-2009, 07:31 AM
try to record a macro do a first instance manually, find the (') apostrophe, then delete the whole paragraph... stop the macro.. then try running again the macro..check if it will works..

back-up files before trying to do something :)

fumei
06-24-2009, 11:38 AM
You do not state what it is you did for your recording. It looks like you used Find, in which case, yes, Find will all instances of ' .

Here is a hint: declare and use a Paragraph object. Test the first character, and if it is "'" - apostrophe - then delete the paragraph.

You do NOT, repeat NOT, have to: "Select entire line (paragraph)"

You do NOT have to select anything in order to do this.

Here, I will expand the hint:
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs()
' do your actions
Next

Jinky Julie
07-08-2009, 04:43 AM
Hi all...

Found a solution on another site... Thanks anyway...


Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "'"
While .Execute
oRng.Paragraphs(1).Range.Delete
Wend
End With

fumei
07-08-2009, 01:06 PM
Have you actually tested/used that? Because in one of your posts you stated:

"Word is finding all instances of ' not just the lines beginning with it... that is not what I want to do..."

Using the example below:

This is a paragraph that can’t be deleted.

with the ' NOT at the beginning (it is in "can't"), then....
the code you say works WILL delete that paragraph, even though it does not start with '.

That code does the same thing. It finds all instances of '. It does this for the same reason I have already stated...it uses .Find.

macropod
07-09-2009, 10:51 PM
Hi Jinky Julie,

As fumei says, you macro will delete paragraphs wherever the "'" appears.

Try:

Sub CleanUp()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "'"
While .Execute
With oRng.Paragraphs(1).Range
If .Characters(1) = "'" Then .Delete
End With
Wend
End With
End Sub

fumei
07-10-2009, 10:58 AM
Bingo.

Jinky Julie
07-29-2009, 05:43 AM
Thank you Macropod... for your help...

J