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.

Please support us!