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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
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?
 

RichieRich

Board Regular
Joined
Jul 10, 2002
Messages
88
Which line of code is giving you trouble? Can you post the Auto_Close routine?
 

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424

ADVERTISEMENT

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
 

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424

ADVERTISEMENT

THE ERROR WAS A RUN TIME ERROR, TYPE MISMATCH.

THANKS.
 

rikrak

Active Member
Joined
Aug 21, 2002
Messages
255
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
 

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
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.
 

Forum statistics

Threads
1,148,173
Messages
5,745,179
Members
423,931
Latest member
thangvan114

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
Top