User Tools

Site Tools


microsoft_excel:macro_master_run_routine

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
microsoft_excel:macro_master_run_routine [2016/07/11 11:26] – created petermicrosoft_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 'master' controlling routine, which also times how long other routines take and displays messages. 
-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                       ' Workbook Name 
-    wb_name = ThisWorkbook.name 
- 
-    ' Control to prevent user from overwriting the template. 
-    If ThisWorkbook.name Like "* Template.xlsm" Then 
-        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 = "" Then 
-        Application.StatusBar = "Running " & strQueryName 
-    Else 
-        Application.StatusBar = "Running " & strDescription 
-    End If 
-     
-     
-    ' Run query. 
-    'DoCmd.OpenQuery strQueryName, acNormal 
-    '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("Dashboard").Activate 
-    End If 
-    
-         
-    ' Display how long the subroutine ran for. 
-    sngEnd = Timer                                 ' Get end time. 
-    sngElapsed = Format(sngEnd - sngStart, "Fixed") ' Elapsed time. 
- 
- 
-    ' Make excel top most to bring it to the top of other applications. 
-    SetXLOnTop 
-         
-         
-    ' Display message to user. 
-    If strDescription = "" Then 
-        Message "", sngElapsed, strQueryName 
-        Application.StatusBar = "Finished " & strQueryName 
-    Else 
-        Message "", sngElapsed, strDescription 
-        Application.StatusBar = "Finished " & strDescription 
-    End If 
-         
-         
-    ' Make excel not top most to allow other applications to go on top of it. 
-    SetXLNormal 
-         
-End Sub 
-</code> 
  
microsoft_excel/macro_master_run_routine.1468236380.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki