microsoft_excel:macro_master_run_routine
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
microsoft_excel:macro_master_run_routine [2016/07/11 11:26] – created peter | microsoft_excel:macro_master_run_routine [2021/08/04 14:22] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Master Run Routine ====== | ||
- | |||
- | This is a suggested master run routine. | ||
- | |||
- | <code excel> | ||
- | ' Runs whichever subroutine name is passed to it. | ||
- | ' This is the ' | ||
- | Sub Z99999_Run_Subroutine(strQueryName As String, Optional strDescription As String = "" | ||
- | |||
- | Dim sngStart As Single | ||
- | Dim sngEnd As Single | ||
- | Dim sngElapsed As Single | ||
- | |||
- | ' Set a shortcut to the workbook. | ||
- | ' wb_name is declared global as Public wb_name As String | ||
- | wb_name = ThisWorkbook.name | ||
- | |||
- | ' Control to prevent user from overwriting the template. | ||
- | If ThisWorkbook.name Like "* Template.xlsm" | ||
- | MsgBox "This workbook is the template, you must not make changes to it." & vbCrLf & vbCrLf & "You need to save as a new workbook name before running any macros." | ||
- | Exit Sub | ||
- | End If | ||
- | |||
- | |||
- | ' Get start time. | ||
- | sngStart = Timer | ||
- | | ||
- | | ||
- | ' Initializes global variables. | ||
- | Call Z00000_Init | ||
- | |||
- | | ||
- | ' To speed up processing. | ||
- | If ctrl_disable_auto_calcs_before_subroutine Then | ||
- | With Application | ||
- | .Calculation = xlCalculationManual | ||
- | .EnableEvents = False | ||
- | .ScreenUpdating = False | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | ' Turn filters off on all sheets. | ||
- | Call TurnFilterOffAllSheets | ||
- | | ||
- | | ||
- | ' Update StatusBar message. | ||
- | If strDescription = "" | ||
- | Application.StatusBar = " | ||
- | Else | ||
- | Application.StatusBar = " | ||
- | End If | ||
- | | ||
- | | ||
- | ' Run query. | ||
- | ' | ||
- | 'Call strQueryName | ||
- | Application.Run strQueryName | ||
- | | ||
- | | ||
- | ' Re-enable automatic calculations. | ||
- | If ctrl_reenable_auto_calcs_after_subroutine Then | ||
- | With Application | ||
- | .Calculation = xlCalculationAutomatic | ||
- | .EnableEvents = True | ||
- | .ScreenUpdating = True | ||
- | End With | ||
- | End If | ||
- | | ||
- | |||
- | ' Activate the dashboard. | ||
- | If ctrl_show_dashboard_after_subroutine Then | ||
- | Workbooks(wb_name).Sheets(" | ||
- | End If | ||
- | |||
- | | ||
- | ' Display how long the subroutine ran for. | ||
- | sngEnd = Timer ' | ||
- | sngElapsed = Format(sngEnd - sngStart, " | ||
- | |||
- | |||
- | ' Make excel top most to bring it to the top of other applications. | ||
- | SetXLOnTop | ||
- | | ||
- | | ||
- | ' Display message to user. | ||
- | If strDescription = "" | ||
- | Message "", | ||
- | Application.StatusBar = " | ||
- | Else | ||
- | Message "", | ||
- | Application.StatusBar = " | ||
- | End If | ||
- | | ||
- | | ||
- | ' Make excel not top most to allow other applications to go on top of it. | ||
- | SetXLNormal | ||
- | | ||
- | End Sub | ||
- | </ | ||
microsoft_excel/macro_master_run_routine.1468236380.txt.gz · Last modified: 2020/07/15 09:30 (external edit)