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