Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' MOpenClose
- ' Description: This module contains the application startup and shutdown code.
- ' It must not contain any code that won't compile in old versions,
- ' nor anything that calls external object models that might not be
- ' installed on the user's computer
- '
- ' Authors: Rob Bovey, www.appspro.com
- ' Stephen Bullen, www.oaltd.co.uk
- '
- ' Chapter Change Overview
- ' Ch# Comment
- ' --------------------------------------------------------------
- ' 05 Initial version
- '
- Option Explicit
- Option Private Module
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This routine is run every time the application is
- ' opened. It initializes the application.
- '
- ' Arguments: None
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Sub Auto_Open()
- Dim wkbBook As Workbook
- ' The very first thing your application should do upon
- ' startup is attempt to delete any copies of its
- ' command bars that may have been left hanging around
- ' by an Excel crash or other incomplete exit.
- On Error Resume Next
- Application.CommandBars(gsBAR_TOOLBAR).Delete
- On Error GoTo 0
- ' Initialize global variables.
- InitGlobals
- ' Make sure we can locate our time entry workbook before we
- ' do anything else.
- If Len(Dir$(gsAppDir & gsFILE_TIME_ENTRY)) > 0 Then
- Application.ScreenUpdating = False
- Application.StatusBar = gsSTATUS_LOADING_APP
- ' Build the command bars.
- BuildCommandBars
- ' Determine if the time entry workbook is already open.
- ' If not, open it. If so, activate it.
- On Error Resume Next
- Set wkbBook = Application.Workbooks(gsFILE_TIME_ENTRY)
- On Error GoTo 0
- If wkbBook Is Nothing Then
- Set wkbBook = Application.Workbooks.Open( _
- gsAppDir & gsFILE_TIME_ENTRY)
- Else
- wkbBook.Activate
- End If
- ' Make the worksheet settings for the time entry
- ' workbook
- MakeWorksheetSettings wkbBook
- ' Reset critical application properties.
- ResetAppProperties
- Else
- MsgBox gsERR_FILE_NOT_FOUND, vbCritical, gsAPP_NAME
- ShutdownApplication
- End If
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This routine runs automatically every time the
- ' application workbook is closed. If the application
- ' shutdown code is not already running (as the result
- ' of a call from the Exit button), this procedure
- ' calls the application shutdown procedure.
- '
- ' Arguments: None
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Sub Auto_Close()
- ' Call standard shutdown code if it isn't already running.
- If Not gbShutdownInProgress Then ShutdownApplication
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This routine shuts down the application.
- '
- ' Arguments: None
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Sub ShutdownApplication()
- ' Ignore any errors on application shutdown.
- On Error Resume Next
- ' This flag prevents this procedure from being called a
- ' second time by Auto_Close if it has already been called
- ' by the ExitApplication procedure.
- gbShutdownInProgress = True
- ' Delete command bar.
- Application.CommandBars(gsBAR_TOOLBAR).Delete
- ' Close the time entry workbook, allowing the user to
- ' save changes.
- Application.Workbooks(gsFILE_TIME_ENTRY).Close
- ' If there are no workbooks left open, quit Excel
- ' Otherwise just close this workbook.
- If lCountVisibleWorkbooks() = 0 Then
- ThisWorkbook.Saved = True
- Application.Quit
- Else
- ThisWorkbook.Close False
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment