WPS 基础接口 > 文字 API 参考 > Document > 事件 > Document.New 事件
在创建基于模板的新文档时发生。仅当 New 事件的过程存储在模板中时,才可运行该过程。

语法

Private Sub 表达式_Private Sub Document_New

表达式   一个代表 Document 对象的变量。

说明

有关配合使用事件与 Document 对象的信息,请参阅 配合使用事件与 Document 对象。

示例

以下示例在创建基于模板的新文档时,询问用户是否要保存已打开的所有其他文档。(此过程存储在模板的 ThisDocument 类模块中,而不是在文档中。)

示例代码
function Document_New() {
    let intResponse
    let strName
    let docLoop

    intResponse = MsgBox("Save all other documents?", jsYesNo)

    if(intResponse == jsResultYes) {
        strName = ActiveDocument.Name
        for(let i = 1 ; i <= Application.Documents.Count ; i++) {
            docLoop = Application.Documents.Item(i)
            if(docLoop.Name != strName) {
                docLoop.Save()
            }
        }
    }
}


请参阅