Results 1 to 5 of 5

Thread: Simple Text Selection Code in Word That is Killing me!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Burbank
    Posts
    6

    Angry

    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

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    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

  3. #3
    Addicted Member c@lle's Avatar
    Join Date
    Oct 1999
    Location
    Belgium
    Posts
    179
    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

  4. #4
    Addicted Member c@lle's Avatar
    Join Date
    Oct 1999
    Location
    Belgium
    Posts
    179
    what exactly do you want to archieve? The code you posted is working fine, so what is the problem?
    please let me know?

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Burbank
    Posts
    6

    Angry 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width