wsnyder
Board Regular
- Joined
- Sep 23, 2018
- Messages
- 223
- Office Version
- 365
- Platform
- Windows
Hi all,
Is it ok to call my sub multiple times as I am doing below?
Is there a better way to make sure the sub executes?
Thanks,
-w
Is it ok to call my sub multiple times as I am doing below?
Is there a better way to make sure the sub executes?
Thanks,
-w
VBA Code:
Sub foo()
Dim olApp As Object
Call ShutdownExcelEvironment
On Error Resume Next
Set olApp = CreateObject("Outlook.Application")
If Not olApp Is Nothing Then
'Object exists continue
Else
MsgBox "The Outlook Application does not exist"
Debug.Print "reached"
Call RestoreExcelEvironment
Exit Sub
End If
Debug.Print "ta-da!"
Call RestoreExcelEvironment
End Sub
Public Sub ShutdownExcelEvironment()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
.DisplayAlerts = False
End With
End Sub
Public Sub RestoreExcelEvironment()
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub