insomniac_ut
New Member
- Joined
- Sep 15, 2005
- Messages
- 36
Hello,
I have 3-4 workbooks that I calculate every morning and I'd like to automate these so that they run overnight as part of a scheduled task.
I have written some code to open the workbooks, perform the calculations, save the workbooks and close Excel.
Of these 4 steps, the code performs the first two without a problem. However, the last steps are not performed and the Excel session remains open after finishing the calculations.
The code runs as follows:
Private Sub Workbook_Open()
Application.Calculation = xlCalculationManual
If Environ("Automatic") = "TRUE" Then
Call FirstButton
ThisWorkbook.Save
ThisWorkbook.Close
Application.DisplayAlerts = False
Environ("Automatic") = "FALSE"
Application.Quit
End If
End Sub
With the FirstButton method:
Public Sub FirstButton()
Worksheets("Current Points").UsedRange.Calculate
Worksheets("Floors").UsedRange.Calculate
Worksheets("Rolldown").UsedRange.Calculate
Worksheets("Summary").UsedRange.Calculate
Worksheets("Summary").Activate
End Sub
I was hoping that I could get some pointers as to what the problem might be?
Thanks in advance.
I have 3-4 workbooks that I calculate every morning and I'd like to automate these so that they run overnight as part of a scheduled task.
I have written some code to open the workbooks, perform the calculations, save the workbooks and close Excel.
Of these 4 steps, the code performs the first two without a problem. However, the last steps are not performed and the Excel session remains open after finishing the calculations.
The code runs as follows:
Private Sub Workbook_Open()
Application.Calculation = xlCalculationManual
If Environ("Automatic") = "TRUE" Then
Call FirstButton
ThisWorkbook.Save
ThisWorkbook.Close
Application.DisplayAlerts = False
Environ("Automatic") = "FALSE"
Application.Quit
End If
End Sub
With the FirstButton method:
Public Sub FirstButton()
Worksheets("Current Points").UsedRange.Calculate
Worksheets("Floors").UsedRange.Calculate
Worksheets("Rolldown").UsedRange.Calculate
Worksheets("Summary").UsedRange.Calculate
Worksheets("Summary").Activate
End Sub
I was hoping that I could get some pointers as to what the problem might be?
Thanks in advance.