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.

Sự kiện

Một vĩ lệnh đã gán được thực hiện...

routine

Khởi chạy ứng dụng

...after a LibreOffice application is started.

OnStartApp

Đóng ứng dụng

...trước khi kết thúc một ứng dụng LibreOffice.

OnCloseApp

Tài liệu được tạo

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

OnCreate

Tài liệu mới

...sau khi một tài liệu mới được tạo bằng lệnh Tập tin > Mới hoặc bằng biểu tượng Mới.

OnNew

Nạp xong tài liệu

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

OnLoadFinished

Mở tài liệu

...sau khi một tài liệu được mở bằng lệnh Tập tin > Mở hoặc bằng biểu tượng Mở.

OnLoad

Tài liệu đang được đóng

...trước khi đóng tài liệu.

OnPrepareUnload

Đóng tài liệu

...sau khi đóng tài liệu. Lưu ý rằng sự kiện "Lưu tài liệu" cũng có thể xảy ra khi tài liệu được lưu trước khi đóng.

OnUnload

-no UI-

OnLayoutFinished

Đã taọ khung nhìn

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

OnViewCreated

Khung nhìn đang được đóng

Document layout is getting removed.

OnPrepareViewClosing

Đã đóng khung nhìn

Document layout is cleared prior to the document closure.

OnViewClosed

Kích hoạt tài liệu

...sau khi một tài liệu được nâng lên trên.

OnFocus

Khử hoạt tài liệu

...sau khi tài liệu khác được nâng lên trên.

OnUnfocus

Lưu tài liệu

...trước khi một tài liệu được lưu bằng lệnh Tập tin > Lưu hoặc bằng biểu tượng Lưu, miễn là đã xác định một tên cho tài liệu.

OnSaveAs

Tài liệu đã được lưu

...sau khi một tài liệu được lưu bằng lệnh Tập tin > Lưu hoặc biểu tượng Lưu, miễn là đã xác định một tên cho tài liệu.

OnSaveDone

Không lưu tài liệu được

Document could not be saved.

OnSaveFailed

Lưu mới tài liệu

...trước khi một tài liệu được lưu dưới một tên cụ thể (dùng lệnh Tập tin > Lưu mới, hoặc dùng lệnh Tập tin > Lưu hoặc biểu tượng Lưu nếu chưa ghi rõ tên tài liệu).

OnSaveAs

Tài liệu đã được lưu dưới dạng

...sau khi một tài liệu được lưu với một tên cụ thể (dùng lệnh Tập tin > Lưu mới, hoặc dùng lệnh Tập tin > Lưu hoặc biểu tượng Lưu nếu chưa ghi rõ tên tài liệu).

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

Lưu trữ hoặc xuất bản sao tài liệu

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

OnCopyTo

Đã tạo bản sao tài liệu

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

OnCopyToDone

Không tạo được bản sao tài liệu

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

Trạng thái "sửa đổi" bị thay đổi

Modified state of a document has changed.

OnModifyChanged

Đã thay đổi tiêu đề của tài liệu

When the document title gets updated.

OnTitleChanged

Đã nạp một thành phần phụ

...after a database form has been opened.

OnSubComponentOpened

Đã đóng một thành phần phụ

...after a database form has been closed.

OnSubComponentClosed

Bắt đầu in thư theo mẫu

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

OnMailMerge

Kết thúc in thư theo mẫu

...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

Hiệu đếm trang

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.


Gán một vĩ lệnh cho một sự kiện

  1. Chọn mục trình đơn Công cụ > Tùy biến, sau đó nhấn vào phiếu Sự kiện.

  2. Trong hộp liệt kê Lưu vào, chọn nếu bạn muốn sự gán này là hợp lệ toàn cục hoặc chỉ hợp lệ trong tài liệu hiện tại.

  3. Chọn sự kiện trong danh sách các Sự kiện.

  4. Nhấn vào nút Vĩ lệnh, sau đó chọn vĩ lệnh cần gán cho sự kiện đã chọn.

  5. Nhấn vào nút OK để gán vĩ lệnh.

  6. Nhấn vào nút OK để đóng hộp thoại.

Gỡ bỏ phép gán vĩ lệnh cho một sự kiện

  1. Chọn mục trình đơn Công cụ > Tùy biến, sau đó nhấn vào phiếu Sự kiện.

  2. Chọn nếu bạn muốn gỡ bỏ một sự gán toàn cục hoặc một sự gán chỉ hợp lệ trong tài liệu hiện tại, bằng cách bật tùy chọn đó trong hộp liệt kê Lưu vào.

  3. Chọn sự kiện có phép gán cần gỡ bỏ trong danh sách các sự kiện.

  4. Nhấn vào nút Bỏ.

  5. Nhấn vào nút OK để đóng hộp thoại.

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

Please support us!