Reply
 
Thread Tools Display Modes
  #1   Report Post  
Bob Frolek
 
Posts: n/a
Default Delete first words in all paragraphs

Does someone have a macro that will delete the first fifteen words in
all paragraphs in a Word document and delete all paragraphs with less
than 16 words? Thanks

  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Bob Frolek wrote:
Does someone have a macro that will delete the first fifteen words in
all paragraphs in a Word document and delete all paragraphs with less
than 16 words? Thanks


Hi Bob,

Why would anyone have such a special-purpose macro lying around? ;-)

You could write something like this:

Sub Delete15Words()
Dim oPar As Paragraph
Dim i As Integer
For Each oPar In ActiveDocument.Paragraphs
With oPar.Range
If .Words.Count 16 Then
.Delete
Else
For i = 1 To 15
.Words(1).Delete
Next i
End If
End With
Next oPar
End Sub

But you'd probably be disappointed with the results. The problem is that the
..Words collection in VBA doesn't agree with most people's intuitive
understanding of what a word is, nor does it agree with the Tools Word
Count dialog. For the purposes of the .Words collection, each punctuation
mark and each (normally invisible) paragraph mark counts as a "word"! If
your "first 15 words" include any commas, periods, question marks,
exclamation points, semicolons, or colons, the macro will delete too few
words.

In any case, the test should be changed to

If .Words.Count 17 Then

because the paragraph mark at the end of a 15-word paragraph would make
..Words.Count = 16 and you still want to delete the whole paragraph.

What are the 15 words? If they always fit the same pattern, you might do
better with a wildcard search
(http://www.gmayor.com/replace_using_wildcards.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


  #3   Report Post  
Bob Frolek
 
Posts: n/a
Default

Thanks, Jay. Macro works beautifully. Word count I can work around.
Words in first part of para are always different and there's no
pattern.

Jay Freedman wrote:
Bob Frolek wrote:
Does someone have a macro that will delete the first fifteen words in
all paragraphs in a Word document and delete all paragraphs with less
than 16 words? Thanks


Hi Bob,

Why would anyone have such a special-purpose macro lying around? ;-)

You could write something like this:

Sub Delete15Words()
Dim oPar As Paragraph
Dim i As Integer
For Each oPar In ActiveDocument.Paragraphs
With oPar.Range
If .Words.Count 16 Then
.Delete
Else
For i = 1 To 15
.Words(1).Delete
Next i
End If
End With
Next oPar
End Sub

But you'd probably be disappointed with the results. The problem is that the
.Words collection in VBA doesn't agree with most people's intuitive
understanding of what a word is, nor does it agree with the Tools Word
Count dialog. For the purposes of the .Words collection, each punctuation
mark and each (normally invisible) paragraph mark counts as a "word"! If
your "first 15 words" include any commas, periods, question marks,
exclamation points, semicolons, or colons, the macro will delete too few
words.

In any case, the test should be changed to

If .Words.Count 17 Then

because the paragraph mark at the end of a 15-word paragraph would make
.Words.Count = 16 and you still want to delete the whole paragraph.

What are the 15 words? If they always fit the same pattern, you might do
better with a wildcard search
(http://www.gmayor.com/replace_using_wildcards.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My backspace key will not delete entire words wordnerd Microsoft Word Help 1 July 8th 05 03:48 AM
Finding, cutting and pasting multiple words and paragraphs with ma Nexan Microsoft Word Help 6 March 2nd 05 05:49 PM
How to delete misspelled words Sara Microsoft Word Help 1 January 13th 05 12:28 AM
How do I delete Word's list of reviewers? cccword Microsoft Word Help 1 January 7th 05 12:06 AM
How do you delete words from the dictionary from Office 2000 Library Microsoft Word Help 1 November 29th 04 04:53 PM


All times are GMT +1. The time now is 06:36 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"