【问题标题】:change the value of a word custom field with vba使用 vba 更改单词自定义字段的值
【发布时间】:2020-03-11 07:48:16
【问题描述】:

我使用 VBA 从 excel 文件中读取数据并将其插入到 word 文档中。 现在我被困在如何更改“自定义单词字段”的值上。 我在单词菜单(菜单->信息->属性->高级属性->自定义)的单词文档中添加了一个字段。 这是我如何添加自定义字段的指南: click me

我的字段名为“w_ean”。

我尝试过这样的事情,但我总是收到运行时错误 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

【问题讨论】:

标签: excel vba ms-word


【解决方案1】:

虽然您的文档中可能有一个DocProperty 字段,但您不能直接设置它的值。而是设置您创建的以及该字段所引用的 CustomProperty 的值。

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

设置属性值后,您需要更新文档中的字段以显示正确的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2022-12-15
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    相关资源
    最近更新 更多