我正在使用后期绑定来创建一个 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
如何声明该方法,以便编译器不标记它?