0
votes

i use VBA to read data from an excel file and insert it into an word document. Now i am stuck on how i can change the value of an "custom word field". I add a field in the word document in th word menu (menu->info->properties->advanced properties->custom). Here is an Guide how i added the custom fields: click me

my field has the name "w_ean".

I tried something like this, but i always get a runtime error 13..

Function FnOpeneWordDoc()

    Dim objWord
    Dim objDoc


    ' Word Objekt erstellen
    Set objWord = CreateObject("Word.Application")
    ' Word Dokument öffnen
    Set objDoc = objWord.Documents.Open("myFile.docx")
    ' Word sichtbar machen!
    objWord.Visible = True

    objDoc.Fields("w_ean").Result = "123"
End Function
1
You might want to research a bit farther on the topic of what can be used as a "data target" in a Word document: stackoverflow.com/questions/49903311/…Cindy Meister

1 Answers

0
votes

Whilst you may have a DocProperty field in your document you do not set its value directly. Instead you set the value of the CustomProperty that you created and to which the field refers.

objDoc.CustomProperties("w_ean").Value = "123"

After you have set the value of the property you will need to update the fields in your document so that the correct value is displayed.