Document Event-Driven Macros

This section describes how to assign scripts to application, document or form events.

You can automatically execute a macro when a specified software event occurs by assigning the desired macro to the event. The following table provides an overview of document events and at what point an assigned macro is executed.

事件

指定的宏已执行...

routine

Start Application

...after a LibreOffice application is started.

OnStartApp

Close Application

...LibreOffice 应用程序终止之前。

OnCloseApp

Document created

...New document created with File - New or with the New icon. Note that this event also fires when Basic IDE opens.

OnCreate

New Document

...通过选择「文件 - 新建」或点击「新建」图标创建新文档之后。

OnNew

Document loading finished

...before a document is opened with File - Open or with the Open icon.

OnLoadFinished

文档打开

...通过选择「文件 - 打开」或点击「打开」图标打开文档之后。

OnLoad

Document is going to be closed

...文档关闭之前。

OnPrepareUnload

文档已经关闭

...文档关闭之后。请注意,在文档关闭之前进行保存时,也会发生「保存文档」事件。

OnUnload

-no UI-

OnLayoutFinished

View created

Document is displayed. Note that this event also happens when a document is duplicated.

OnViewCreated

View is going to be closed

Document layout is getting removed.

OnPrepareViewClosing

View closed

Document layout is cleared prior to the document closure.

OnViewClosed

激活文档

...文档显示在前景之后。

OnFocus

停用文档

...另一个文档显示在前景之后。

OnUnfocus

文档保存

...通过「文件 - 保存」或「保存」图标保存文档之前 (假设已指定文档名称)。

OnSaveAs

文档已经保存

...通过「文件 - 保存」或「保存」图标保存文档之后 (假设已指定文档名称)。

OnSaveDone

Saving of document failed

Document could not be saved.

OnSaveFailed

文档另存为

...以指定名称保存文档之前 (要另存文档,请选择「文件 - 另存为;如果尚未指定文档名称,请选择文件 - 保存」或点击「保存」图标保存)。

OnSaveAs

文档已经另存为

以指定名称保存文档之后 (要另存文档,请选择「文件 - 另存为;如果尚未指定文档名称,请选择文件 - 保存」或点击「保存」图标保存)。

OnSaveAsDone

'Save As' has failed

Document could not be saved.

OnSaveAsFailed

-no UI-

When the document disk location has changed, for example after a File - Save As action.

OnStorageChanged

Storing or exporting copy of document

...before a document is saved with File - Save a Copy, File - Export, File - Export as PDF or the Save icons.

OnCopyTo

Document copy has been created

...after a document is saved with File - Save a Copy, File - Export, File - Export as PDF or the Save icons.

OnCopyToDone

Creating of document copy failed

Document could not be copied or exported.

OnCopyToFailed

Print document

...after the Print dialog is closed, but before the actual print process begins. This event occurs for each copy printed.

OnPrint

-no UI-

...after document security settings have changed.

OnModeChanged

'Modified' status was changed

Modified state of a document has changed.

OnModifyChanged

Document title changed

When the document title gets updated.

OnTitleChanged

Loaded a sub component

...after a database form has been opened.

OnSubComponentOpened

Closed a sub component

...after a database form has been closed.

OnSubComponentClosed

Printing of form letters started

...before printing form letters using File - Print or Tools - Mail Merge Wizard menus.

OnMailMerge

Printing of form letters finished

...after printing of form letters using File - Print or Tools - Mail Merge Wizard menus.

OnMailMergeFinished

Printing of form fields started

...before printing form fields.

OnFieldMerge

Printing of form fields finished

...after printing form fields.

OnFieldMergeFinished

修改页数

When the page count changes.

OnPageCountChanged


note

Most events relate to documents, except OnStartApp, OnCloseApp, OnCreate and OnLoadFinished that occur at application level. OnSubComponentOpened, and OnSubComponentClosed events are fired by database's forms.


tip

Writer documents are triggering those specific events: OnLayoutFinished, OnMailMerge, OnMailMergeFinished, OnFieldMerge, OnFieldMergeFinished and OnPageCountChanged.


为事件指定宏

  1. 选择「工具 - 自定义」,然后点击「事件」选项卡。

  2. 在「保存于」列表框中,您可以选择是将宏指定指定为全局有效,或是仅在当前文档中有效。

  3. 从「事件」列表中选择事件。

  4. 点击「」,并选择要指定到选中事件的宏。

  5. 点击「确定」指定宏。

  6. 点击「确定」关闭对话框。

取消为事件指定的宏

  1. 选择「工具 - 自定义」,然后点击「事件」选项卡。

  2. 在「保存于」列表框中,您可以选择取消将宏指定为全局有效,或是取消仅在当前文档中有效。

  3. 从「事件」列表中选择含有要取消所指定的宏的事件。

  4. 点击「删除」。

  5. 点击「确定」关闭对话框。

In addition to assigning macros to events, one can monitor events triggered in LibreOffice documents.

请支持我们!