Consulting

Results 1 to 3 of 3

Thread: [VBA] Word paragraph, typebackspace

  1. #1

    [VBA] Word paragraph, typebackspace

    I need to apply typebackspace to every paragraph, when
    1. it is not empty
    2. not containing symbols ■ and ★

    e.g. ( each line represents a paragraph )

    The original document looks like:

    ■ ******
    ***xx
    ★******xx
    ***x

    ■ *********x
    ***xx xx
    ★*********x
    ***x ***


    After VBA execution, it becomes:

    ■ *********xx
    ★************

    ■ *************** xx
    ★************xx ***


    With Selection
     For i = .Paragraphs.Count To 1 Step -1
                '-------------------
                 If (InStr(1, .Paragraphs(i).Range.Text, "■") = 0) And (InStr(1, .Paragraphs(i).Range.Text, "★") = 0) And .Paragraphs(i).Range.Text <> "" Then
                    .Paragraphs(i).Range.Select
                    Selection.HomeKey
                    Selection.TypeBackspace
                End If
                '-------------------
            Next
    End Selection
    But it returns error for the [B] [B/] line.
    Please help.Thanks.

  2. #2
    The before and after do not seem to correlate to one another, however what I think you want is

    Dim oPara As Paragraph
    Dim i As Integer
        For i = ActiveDocument.Paragraphs.Count To 2 Step -1
            Set oPara = ActiveDocument.Paragraphs(i)
            If Len(oPara.Range) > 1 Then
                If Not oPara.Range.Characters(1) = ChrW(9632) And _
                   Not oPara.Range.Characters(1) = ChrW(9733) Then
                        oPara.Range.Previous.Characters.Last.Delete
                End If
            End If
        Next i
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Thanks sir!

Posting Permissions

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