"代码" 属性 (Word)Field.Code property (Word)

返回一个**Range** 对象, 该对象代表域的代码。Returns a Range object that represents a field's code. 读/写。Read/write.

语法Syntax

expressionexpression. Code

_表达式_一个代表 "Field" 对象的变量。expression A variable that represents a 'Field' object.

注解Remarks

域代码是包含在域字符 ({ }) 中的所有内容,包括前导和尾部空格。A field's code is everything that's enclosed by the field characters ({ }) including the leading space and trailing space characters. 无需更改域结果的显示方式即可访问域代码。You can access a field's code without changing the view from field results.

示例Example

本示例显示活动文档中每一个域的域代码。This example displays the field code for each field in the active document.

Dim fieldLoop As Field 
 
For Each fieldLoop In ActiveDocument.Fields 
 MsgBox Chr(34) & fieldLoop.Code.Text & Chr(34) 
Next fieldLoop

本示例将活动文档中第一个域的域代码改为 CREATEDATE。This example changes the field code for the first field in the active document to CREATEDATE.

Dim rngTemp As Range 
 
Set rngTemp = ActiveDocument.Fields(1).Code 
rngTemp.Text = " CREATEDATE " 
ActiveDocument.Fields(1).Update

本示例判断活动文档中是否包含一个名为"Title"的邮件合并域。This example determines whether the active document includes a mail merge field named "Title."

Dim fieldLoop As Field 
 
For Each fieldLoop In ActiveDocument.MailMerge.Fields 
 If InStr(1, fieldLoop.Code.Text, "Title", 1) Then 
 MsgBox "A Title merge field is in this document" 
 End If 
Next fieldLoop

另请参阅See also

Field 对象Field Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.