Building Word fields

独自空忆成欢 提交于 2019-11-30 15:58:56

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!