1

我在 MS Word Visual Basic 编辑器中有这个 VBA 代码;

它旨在重置页码,以便它们连续工作。但是,它似乎跳过了循环的全部内容而不执行它。

Sub Macro3()
'
' Macro3 Macro
' Test 3
'
Dim GetNumberOfPages

    For IncVar = 1 To GetNumberOfPages
        WordBasic.ViewFooterOnly
        ActiveDocument.AttachedTemplate.BuildingBlockEntries(" Blank").Insert _
            Where:=Selection.Range, RichText:=True
        WordBasic.ViewFooterOnly
        ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number 3"). _
            Insert Where:=Selection.Range, RichText:=True
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
        Selection.WholeStory
        With Selection.Sections(IncVar).Headers(IncVar).PageNumbers
            .NumberStyle = wdPageNumberStyleArabic
            .HeadingLevelForChapter = 0
            .IncludeChapterNumber = False
            .ChapterPageSeparator = wdSeparatorHyphen
            .RestartNumberingAtSection = False
            .StartingNumber = 0
        End With
        Selection.WholeStory
        Selection.EscapeKey
        ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
            ShowAll
        Selection.EscapeKey
        Selection.EscapeKey
    Next IncVar
End Sub

为什么是这样?我该如何解决?

谢谢,

巴里·史密斯

4

3 回答 3

5

如果您使用f8Step Into...的序列并检查您的值,GetNumberOfPages您将看到GetNumberOfPages = Empty整个循环被跳过

于 2013-02-20T10:52:40.080 回答
3

GetNumberOfPages是一个变量,默认为空。

您首先需要为其分配一些值,例如

Dim numberOfPages as Integer
Dim currentPage as Integer
numberOfPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
For currentPage = 1 To numberOfPages
    ...
Next currentPage
于 2013-02-20T10:57:41.970 回答
1

我想你是这样想的

Dim GetNumberOfPages as integer = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) //check the syntax . i'm not sure. 

但是忘记初始化GetNumberOfPages

于 2013-02-20T10:54:45.573 回答