VBA WORD 段落前加空行

Private Function isBlankLine(s1 As String) As Boolean ‘判断是否为空白行
‘9 TAB 32 空格 13 换行
l1 = Len(s1)

For i = 1 To l1
ch = Asc(Mid(s1, i, 1))
    If (ch <> 9 And ch <> 32 And ch <> 13) Then

        isBlankLine = False
        GoTo exit1
    End If
Next i

isBlankLine = True

exit1:
End Function

Private Sub CommandButton1_Click()
Open “D:\SAV.TXT” For Output As #1

pcount = Word.ActiveDocument.Paragraphs.Count
Label1 = pcount
Dim p1 As String
Dim pup As String

With Word.ActiveDocument

For i = 3000 To pcount
DoEvents
Label2 = i

p0 = ActiveDocument.Paragraphs(i).Range.Text
p1 = Left(p0, 5)
If InStr(1, p1, "、") <> 0 Or InStr(1, p1, ".") <> 0 Or InStr(1, p1, ".") <> 0 Or InStr(1, p1, ".") <> 0 Then

'判断是否含有 、 . .
If InStr(1, p1, "、") <> 0 Then
     ps = Split(p1, "、")(0)
ElseIf InStr(1, p1, ".") <> 0 Then
     ps = Split(p1, ".")(0)
ElseIf InStr(1, p1, ".") <> 0 Then
   ps = Split(p1, ".")(0)
'ElseIf InStr(1, p1, ".") <> 0 Then
 '  ps = Split(p1, ".")(0)
End If



'判断、 . .号前面是否为数字
If (IsNumeric(ps)) Then

    '判断前一段是否为空行
  pup = ActiveDocument.Paragraphs(i - 1).Range.Text

    If (Not isBlankLine(pup)) Then
    ListBox1.AddItem (p0)
    Write #1, "P" & i & "   " & p0

      ActiveDocument.Paragraphs(i - 1).Range.InsertAfter (vbCrLf) '插入换行符
      DoEvents
    End If
'TypeParagraph

    End If

End If

Next i
End With

Close #1
End Sub

Private Sub CommandButton2_Click() ‘去段前段后空格
Label1 = ActiveDocument.Paragraphs.Count
For i = 1 To ActiveDocument.Paragraphs.Count
DoEvents
Label2 = i
s1 = ActiveDocument.Paragraphs(i).Range.Text
If (Asc(Left(s1, 1)) = 32) Then
ActiveDocument.Paragraphs(i).Range.Text = Trim(s1)
End If

Next i
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值