{"id":2210,"date":"2013-07-31T22:20:49","date_gmt":"2013-07-31T22:20:49","guid":{"rendered":"https:\/\/www.event1software.com\/kb\/?page_id=2210"},"modified":"2017-07-25T19:18:17","modified_gmt":"2017-07-25T19:18:17","slug":"event-macros","status":"publish","type":"page","link":"https:\/\/www.event1software.com\/services\/kb\/product-documentation\/liberty-reports\/advanced-topics\/event-macros\/","title":{"rendered":"Event Macros"},"content":{"rendered":"
Liberty Reports can run macros that you record to run in response to specific actions. For example, you can record a macro that is run just before refreshing data so you can carry out your own custom steps that might be needed at that time. These macros are called \"Event Macros\" and must be given a specific name when you record them so that Liberty Reports will run them.<\/p>\r\n
Follow these steps to record a macro tied to a Liberty Reports event:<\/p>\r\n
Action<\/th>\r\n | Associated Macro Names<\/th>\r\n <\/tr>\r\n |
---|---|
Liberty Reports: Save As Values<\/td>\r\n | Before_LRSaveAsValues After_LRSaveAsValues<\/td>\r\n <\/tr>\r\n |
Liberty Reports: Refresh Data<\/td>\r\n | Before_LRRefreshData After_LRRefreshData<\/td>\r\n <\/tr>\r\n |
Excel: New Workbook<\/td>\r\n | LR_OnNewWorkbook<\/td>\r\n <\/tr>\r\n |
Excel: Saving a workbook template<\/td>\r\n | LR_OnSaveTemplate<\/td>\r\n <\/tr>\r\n<\/table>\r\nAdvanced Usage<\/h4>\r\nThe default Before and After event macro functionality can be extended by manually editing the recorded macro procedures.<\/p>\r\n Canceling an Event<\/h5>\r\nAll of the events that start with Before_ can be canceled, preventing the action from taking place. To accomplish this, change the macro from a Sub to a Function that returns a Long. To cancel the action, assign a non-zero return value to the function. For example:<\/p>\r\n All of the events that start with After_ can be modified to indicate if the action was successful. To accomplish this, add a Long parameter to the Sub. Liberty Reports will pass the return code from the associated action via this parameter. Zero indicates success and other values indicate cancellation or errors. For example:<\/p>\r\n |