CLOSING EXCEL WITH MACROS

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
WHAT CODE DO YOU USE IN THE AUTO CLOSE SUB TO CLOSE THE ENTIRE EXCEL PROGRAM (NOT JUST THE WORKSHEETS OR WORKBOOKS)?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
THANKS. I REPLACED "ACTIVEWORKBOOK.CLOSE" WITH "APPLICATION.QUIT" IN THE AUTO CLOSE SUBROUTINE. ON RE-RUNNING THE SUBROUTINE A RUN TIME ERROR TYPE MISMATCH DISPLAYED IN A LINE OF CODE WHICH PREVIOUSLY WORKED O.K. THE LINE OF CODE FLAGGED BY THE ERROR OCCURS MUCH EARLIER IN THE SUBROUTINE THAN "APPLICATION.QUIT". ANY IDEAS?
 
Upvote 0
THE SUBROUTINE FOLLOWS. THE LINE THAT WAS HIGHLIGHTED BY THE VBS EDITER WITH THE ERROR MESSAGE IS "Selection.ClearContents". THIS LINE OPERATED O.K. PRIOR TO REPLACING "ACTIVEWORKBOOK.CLOSE" WITH "APPLICATION.QUIT". THANKS FOR YOUR HELP.



Sub Auto_Close()
'
' Auto_Close Macro
' Macro recorded 9/12/02 by SCIORTINOJJ
'

' Saves data to file on share page.

Dim Test_Run As Single
Dim PS_SN As Variant
Dim Year As Variant
Dim Month As Variant
Dim Day As Variant

Test_Run = Range("run_number")
PS_SN = Range("PS_SN_main")
Year = Range("I13")
Month = Range("J13")
Day = Range("K13")

' Takes out the autodate function

Sheets("Cover Sheet").Visible = True
Sheets("Cover Sheet").Select
Range("date_main3").Select
Selection.ClearContents
Range("date_main3").Value = Month & "/" & Day & "/" & Year
Sheets("Cover Sheet").Visible = False
Sheets("Main Input Form").Select

' If operator does not enter a serial number it will not save the file

If PS_SN = 0 Then

Else

ActiveWorkbook.SaveAs FileName:= _
"D:T400PS Trend" & PS_SN & "-" & Year & _
"-" & Month & Day & "-" & Test_Run & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End If

' Closes workbook

Application.Quit

End Sub
 
Upvote 0
I can't reproduce the error, can you?

What happens when you remove this 2 lines:
Range("date_main3").Select
Selection.ClearContents

this will do:
Range("date_main3").Value = Month & "/" & Day & "/" & Year
 
Upvote 0
THE SUBROUTINE RAN FINE WHEN THOSE TWO LINES WERE REMOVED. I DON'T UNDERSTAND WHY BUT IT'S GREAT THAT IT WORKS. THANKS A LOT.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top