Is it possible to close Excel running vba code in Excel?
I have a workbook that automates a monthly process. This workbook
is started using the windows scheduler but I'd like the code to run
and then close excel entirely so the next time the process is
scheduled the scheduler can run the process again. If excel doesn't
close entirely, the scheduler will not run correctly.
I don't think the actual code will provide any additional insight
into my question but here it is:
Private Sub Workbook_Open()
Dim strWorkbook As String
Dim strFilePath As String
Dim fso As New FileSystemObject
Dim strFilename As String
Dim fil1 As File
Dim ts As TextStream
strWorkbook = ThisWorkbook.Name
strFilePath = ThisWorkbook.Path & "\"
strFilename = "EmailControl.ini"
'MsgBox strFilePath & strFilename
Set fil1 = fso.GetFile(strFilePath & strFilename)
Set ts = fil1.OpenAsTextStream(ForReading)
strFileText = ts.ReadLine
strFirsttwo = Left(strFileText, 2)
If strFirsttwo = "Ye" Then
dblEmailStart = 1
End If
ts.Close
If dblEmailStart = 1 Then
Call EMailCode.emailtest
Application.DisplayAlerts = False
' Would like to close Excel here.
ActiveWorkbook.Close
Application.ActiveWindow.Close
Application.DisplayAlerts = True
End If
End Sub