0

我面临在 Word 文档中断断续续地散落空白页的前景,我想将其丢弃。但我需要先在 VBA 中识别它们。如果我单击工作表,每个插入符号所在的位置都有点。

但我不知道如何从那里进步。如何通过VBA指示Word识别工作表是否有内容?

4

2 回答 2

2

这些线路上的某些东西可能适合。

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
于 2012-04-03T23:30:03.427 回答
0

现在是 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

结束功能

于 2020-05-02T03:07:17.707 回答