Liberty Reports | Online Help |
Event Macros |
Contents | Index |
Liberty Reports can call macros that you record to run at specific time, for example just before refreshing data, so you can carry out steps tied to events in the workbook.StepsFollow these steps to record a macro tied to a Liberty Reports event:
Event Macros List
Advanced UsageThe default Before and After event macro functionality can be extended by manually editing the recorded macro procedures.Canceling an EventAll 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:Public Function Before_LRRefreshData() As Long 'Cancel the refresh if there is no job number If IsEmpty(Range("A1")) Then Call MsgBox("You must enter a job number before refreshing the workbook.", _ vbInformation) Before_LRRefreshData = -1 Exit Function End If End Function Using Return ValuesAll 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:Public Sub After_LRRefreshData(ByVal lvOperationResult As Long) 'Don't do anything if the refresh was canceled or did not complete due to an error If lvOperationResult <> 0 Then Exit Sub End If 'Run the code to perform post-refresh steps here End Sub |