InsertDateTime 方法 (Word)Selection.InsertDateTime method (Word)

以文本或 TIME 域的形式插入当前日期或时间,或将两者都插入。Inserts the current date or time, or both, either as text or as a TIME field.

语法Syntax

expressionexpression. InsertDateTime( _DateTimeFormat_ , _InsertAsField_ , _InsertAsFullWidth_ , _DateLanguage_ , _CalendarType_ )

expression:必需。expression Required. 表示 Selection 对象的变量。A variable that represents a Selection object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
DateTimeFormatDateTimeFormat 可选Optional VariantVariant 显示日期或时间或者同时显示两者时所用的格式。The format to be used for displaying the date or time, or both. 如果省略该参数,Microsoft Word 将使用 Windows“控制面板”(“区域设置” 图标)中的短日期样式。If this argument is omitted, Microsoft Word uses the short-date style from the Windows Control Panel (Regional Settings icon).
InsertAsFieldInsertAsField 可选Optional VariantVariant 要插入指定的 TIME 域的信息。True to insert the specified information as a TIME field. 默认值为 TrueThe default value is True.
InsertAsFullWidthInsertAsFullWidth 可选Optional VariantVariant 要插入双字节数字的形式指定的信息。True to insert the specified information as double-byte digits. 此参数可能不可用,这取决于您所选择或安装的语言支持 (例如美国英语)。This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.
DateLanguageDateLanguage 可选Optional VariantVariant 设置要在其中显示日期或时间的语言。Sets the language in which to display the date or time. 可以是WdDateLanguage常量之一。Can be either of the WdDateLanguage constants. 此参数可能不可用,这取决于您所选择或安装的语言支持 (例如美国英语)。This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.
CalendarTypeCalendarType 可选Optional VariantVariant 设置显示日期或时间时要使用的日历类型。Sets the calendar type to use when displaying the date or time. 可以是WdCalendarTypeBi常量之一。Can be either of the WdCalendarTypeBi constants. 根据您所选择或安装的语言支持(例如,美国英语),此参数可能不可用。This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.

备注Remarks

使用此方法将替换当前所选内容。Using this method replaces the current selection. 若要避免这种情况, 请在使用此方法之前使用**Collapse** 方法。To avoid this, use the Collapse method before using this method.

示例Example

以下示例以 TIME 域的形式插入当前日期。This example inserts a TIME field for the current date. 可能的结果是“11/18/1999”。A possible result might be "November 18, 1999."

Selection.InsertDateTime DateTimeFormat:="MMMM dd, yyyy", _ 
 InsertAsField:=True

另请参阅See also

Selection 对象Selection 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.