MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Closing Excel Window using VBA

  Asked By: Jodon    Date: Feb 15    Category: MS Office    Views: 9830

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


If dblEmailStart = 1 Then
Call EMailCode.emailtest
Application.DisplayAlerts = False

' Would like to close Excel here.

Application.DisplayAlerts = True
End If

End Sub



3 Answers Found

Answer #1    Answered By: Mena Schmidt     Answered On: Feb 15

is the simple answer.

If you place this where you say you want it, the subsequent lines of
code won't be executed.

You've set the DisplayAlerts to False, so the workbook  won't be saved.
I'd guess you want that.

Answer #2    Answered By: Jessie Banks     Answered On: Feb 15

use Application.quit before end if in your code

Answer #3    Answered By: Sam Evans     Answered On: Feb 15

That is exactly what I was looking for.............

Didn't find what you were looking for? Find more on Closing Excel Window using VBA Or get search suggestion and latest updates.