views:

17

answers:

2

I would like to update a Word field from a VBA macro.
The Word Doucument is wrdDoc in the code below.
When I run the code I get a Type mismatch error on retrieving the properties.

If anyone can help I'd be really grateful.

Dim objCustomProperties As CustomProperties
Set objCustomProperties = wrdDoc.CustomDocumentProperties
For i = 1 To objCustomProperties.count
    objCustomProperty = objCustomProperties.Item(i)
Next
A: 

Would you be happy with:

Dim objCustomProperties As Object

?

Remou
A: 

CustomDocumentProperties is a DocumentProperties collection, so that's the type it needs to be (it could also be a Variant or an 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
Otaku