PDA

View Full Version : [VBA] Word paragraph, typebackspace



smallxyz
07-17-2017, 11:10 PM
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.

gmayor
07-18-2017, 12:46 AM
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

smallxyz
07-18-2017, 03:30 AM
Thanks sir!