我面临在 Word 文档中断断续续地散落空白页的前景,我想将其丢弃。但我需要先在 VBA 中识别它们。如果我单击工作表,每个插入符号所在的位置都有点。
但我不知道如何从那里进步。如何通过VBA指示Word识别工作表是否有内容?
这些线路上的某些东西可能适合。
ActiveDocument.Repaginate
j = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
For i = j To 1 Step -1
NotEmpty = True
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
If Selection.Characters.Count < 3 Then
NotEmpty = False
For Each c In Selection.Characters
If Asc(c) > 13 Then
''Possibly not empty
NotEmpty = True
End If
Next
End If
If NotEmpty = False Then
Selection.Delete
End If
Next
现在是 2020 年。从上面略微修改的版本。就我而言,我需要检查 sel.Characters.Count <= 3
. 谢谢!
Public Function DeleteBlankPages()
Dim i, j, notEmpty, c
Dim sel As Selection
myWordDoc.Activate
ActiveDocument.Repaginate
Set sel = ActiveDocument.ActiveWindow.Selection
j = ActiveDocument.BuiltinDocumentProperties(wdPropertyPages)
For i = j To 1 Step -1
notEmpty = True
sel.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
sel.GoTo What:=wdGoToBookmark, Name:="\page"
'Debug.Print "Page", i, " count", sel.Characters.Count
If sel.Characters.Count <= 3 Then
notEmpty = False
For Each c In sel.Characters
If Asc(c) > 13 Then
''Possibly not empty
notEmpty = True
End If
Next
End If
If notEmpty = False Then
sel.Delete
End If
Next
结束功能