WPS 基础接口 > 文字 API 参考 > Application > 事件 > Application.NewDocument 事件
在创建新文档时发生。

语法

Private Sub Application_NewDocument(ByVal Doc As Document)

表达式   一个代表 Application 对象的变量,该对象已使用类模块中的事件声明。

参数

名称 必选/可选 数据类型 说明
Doc 必选 Document 新文档。

说明

有关使用 Application 对象事件的详细信息,请参阅 使用 Application 对象事件。

示例

以下示例在创建新文档时,提示用户是否保存已打开的所有其他文档。为了使本示例能正常运行,以下代码必须放在一个类模块中,而且该类的实例必须正确地初始化。有关如何完成此操作的指导,请参阅 使用 Application 对象事件。

示例代码
function Application_NewDocument(Doc) {
    let intResponse
    let strName

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

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


请参阅