如何在使用后期绑定时声明方法

时间:2013-08-19 08:38:39

标签: ms-access com access-vba

我使用后期绑定来创建一个MsWord对象,从而避免添加引用会导致不同版本的Word出现问题的引用。

Set GetWordObject = CreateObject("Word.Application")

因此,VBA编译器无法识别MsWord常量,我自己一直声明它们如下:

Public Enum wdAutoFitBehaviour
    wdAutoFitContent = 1
    wdAutoFitFixed = 0
    wdAutoFitWindow = 2
End Enum

Public Enum wdSaveOptions
    wdDoNotSaveChanges = 0
    wdPromptToSaveChanges = -2
    wdSaveChanges = -1
End Enum

Public Enum WdParagraphAlignment
    wdAlignParagraphleft = 0
    wdAlignParagraphCenter = 1
    wdAlignParagraphRight = 2
End Enum

Public Enum WdTableDirection
    wdTableDirectionRtl = 0
    wdTableDirectionLtr = 1
End Enum

Public Enum WdGoToItem
    wdGoToTable = 2
End Enum

Public Enum WdGoToDirection
    wdGoToNext = 2
    wdGoToPrevious = 3
End Enum

Public Enum WdUnits
    wdParagraph = 4
    wdCell = 12
End Enum

Public Enum WdDocumentViewDirection
    wdDocumentViewLtr = 1
    wdDocumentViewRtl = 0
End Enum

我的问题是当我需要使用MsWord方法时,例如CentimetersToPoints

With objWordApp.ActiveDocument.PageSetup
    .TopMargin = CentimetersToPoints(0.5)
    .BottomMargin = CentimetersToPoints(0.5)
    .LeftMargin = CentimetersToPoints(0.5)
    .RightMargin = CentimetersToPoints(0.5)
    .PageWidth = CentimetersToPoints(6.5)
    .PageHeight = CentimetersToPoints(11)
End With

如何声明方法,以便编译器不应该标记它?

1 个答案:

答案 0 :(得分:1)

CentimetersToPoints是应用程序对象的一种方法。使用应用程序对象变量的名称限定方法名称。

With objWordApp.ActiveDocument.PageSetup
    .TopMargin = objWordApp.CentimetersToPoints(0.5)