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!