3

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

4

2 回答 2

5

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

我发现 MACROBUTTON 很有用,因为字段内的第三个以空格分隔的条目(以编程方式 field.code.text)显示在 Word 中。这允许我的用户在移动时观察字段。{ MACROBUTTON NoMacro * } 会在 Word 中显示一个“*”,例如当用户双击它时它什么也不做,因为我故意没有定义一个名为“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:

于 2008-11-20T18:01:18.623 回答
2

你想到了什么?可以手动或使用 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

于 2008-10-20T12:45:00.680 回答