构建Word字段

发布于 2024-07-07 17:42:59 字数 102 浏览 11 评论 0原文

除了将文本插入和解析到空白 Word 字段之外,是否有任何方法可以使用 VBA 以编程方式将用户定义的字段和字段代码构建到我自己的模板中? 此外,有没有办法让这些字段显示在可用字段列表中?

Apart from just inserting and parsing text into a blank Word field, is there any way to programmatically build user-defined fields and field codes into my own templates with VBA? Furthermore, is there a way to make these fields show up in the list of available fields?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2024-07-14 17:42:59

我最近开发了一个使用 Word 的 MACROBUTTON 和 ADDIN 字段类型的解决方案。

我发现 MACROBUTTON 很有用,因为字段内的第三个空格分隔条目(以编程方式 field.code.text)显示在 Word 中。 这允许我的用户在移动时观察字段。 { MACROBUTTON NoMacro * }会在Word中显示一个“*”,例如当用户双击它时它不会执行任何操作,因为我故意没有定义名为“NoMacro”的宏。

ADDIN 字段不会显示(除非打开显示字段代码),并在其 field.data 属性中存储隐藏字符串。 使用此字段,我可以有一个隐藏字段,用户无法看到或修改其内容(除非他们打开“显示字段代码”,他们可以看到它是一个 ADDIN 字段(但他们无法查看/编辑“data”属性),并且他们可以像删除任何其他字段一样删除此字段。)

我发现这些页面很有用:

I recently developed a solution that used Word's MACROBUTTON and ADDIN field types.

I found MACROBUTTON useful because the third whitespace-delimited entry inside the field (programmatically field.code.text) is displayed within Word. This allows my users to watch fields as they move around. { MACROBUTTON NoMacro * } would display an "*" in Word, e.g. And it would do nothing when the user double-clicked on it, because I have purposefully not defined a macro named "NoMacro".

The ADDIN field does not display (except when display field codes is turned on) and stores a hidden string in its field.data property. Using this field I could have a hidden field the contents of which could not be seen or modified by users (excepting that if they turn on "show field codes" they can see that it is an ADDIN field (but they cannot see/edit the "data" property), and that they can delete this field just like any other field.)

I found these pages useful:

别在捏我脸啦 2024-07-14 17:42:59

你想到了什么? 可以手动或使用 VBA 添加自定义文档属性。 这些是 DOCPROPERTY 下可访问的字段:

{ DOCPROPERTY "Test"  \* MERGEFORMAT } 

您可以使用宏来确保将自定义属性添加到文档中:

Sub AutoNew()
Dim objCustomProperties As DocumentProperties

Set objCustomProperties = ActiveDocument.CustomDocumentProperties

objCustomProperties.Add Name:="Test", _
   Type:=msoPropertyTypeString, Value:="Blah", _
   LinkToContent:=False

End Sub

更多信息

自动宏:http://msdn.microsoft.com/en-us/library/aa263747(office.10).aspx

了解 Microsoft Office Word 2003 中的自定义文档属性:http://msdn.microsoft .com/en-us/library/aa537154.aspx

What had you in mind? It is possible to add custom document properties either manually or with VBA. These are the accessible as fields under DOCPROPERTY:

{ DOCPROPERTY "Test"  \* MERGEFORMAT } 

You can use a macro to ensure that the custom property is added to documents:

Sub AutoNew()
Dim objCustomProperties As DocumentProperties

Set objCustomProperties = ActiveDocument.CustomDocumentProperties

objCustomProperties.Add Name:="Test", _
   Type:=msoPropertyTypeString, Value:="Blah", _
   LinkToContent:=False

End Sub

Further Information

Automacros: http://msdn.microsoft.com/en-us/library/aa263747(office.10).aspx

Understanding Custom Document Properties in Microsoft Office Word 2003: http://msdn.microsoft.com/en-us/library/aa537154.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文