我想从VBA宏更新Word字段 Word Doucument在下面的代码中是wrdDoc 当我运行代码时,我在检索属性时遇到类型不匹配错误。
如果有人能提供帮助,我会非常感激。
Dim objCustomProperties As CustomProperties
Set objCustomProperties = wrdDoc.CustomDocumentProperties
For i = 1 To objCustomProperties.count
objCustomProperty = objCustomProperties.Item(i)
Next
答案 0 :(得分:1)
CustomDocumentProperties
是一个DocumentProperties
集合,因此它需要的类型(也可以是Variant
或Object
)。
Dim wrdDoc As Document: Set wrdDoc = ActiveDocument
Dim objCustomProperties As DocumentProperties
''# Dim objCustomProperties As Variant ''# This also works
''# Dim objCustomProperties As Object ''# This also works
Set objCustomProperties = wrdDoc.CustomDocumentProperties
For i = 1 To objCustomProperties.Count
''# objCustomProperty = objCustomProperties.Item(i) ''# Your code
Debug.Print objCustomProperties.Item(i).Name & ": " & objCustomProperties.Item(i).Value
Next
答案 1 :(得分:0)
你会满意吗:
Dim objCustomProperties As Object