-
Below is some code writen for the purpose of learning more about Word VBA. This code eliminates consecutive identical paragraphs -- but it is ugly code. How can I cut this down, by identifying the two paragraphs in the If statement? Please help. Thanks.
Sub Macro1()
Selection.HomeKey Unit:=wdStory
For i = 1 To ActiveDocument.Paragraphs.Count - 1
Selection.Paragraphs(1).Range.Select
Nextpara = Selection.Paragraphs(1).Next
If Selection = Nextpara Then
'Why can't this line incorporate the above two lines? Help!
Selection.Delete
Else
Selection.MoveDown Unit:=wdParagraph
End If
Next i
End Sub
-
well I took a shot at it - see if it works
Code:
Sub Macro1()
Dim i As Integer
Selection.HomeKey Unit:=wdStory
i = 1
Do While i < ActiveDocument.Paragraphs.Count
Selection.Paragraphs(i).Range.Select
Nextpara = Selection.Paragraphs(i).Next
If Selection = Nextpara Then
Selection.Delete
Else
i = i + 1
End If
Loop
End Sub
-
what do you mean exactly?
something like this:
Code:
Sub Macro1()
Selection.HomeKey Unit:=wdStory
For i = 1 To ActiveDocument.Paragraphs.Count - 1
If Selection.Paragraphs(1).Range.Select = Selection.Paragraphs(1).Next Then
Selection.Delete
Else
Selection.MoveDown Unit:=wdParagraph
End If
Next i
End Sub
-
what exactly do you want to archieve? The code you posted is working fine, so what is the problem?
please let me know?
-
No Solution Found yet
The above attempts either don't work or don't address the problem. I need the if statement to identify the subject paragraph and the following. HELP!