Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to close Active Excel Window

Status
Not open for further replies.

Scott02

Technical User
Jun 4, 2002
75
US
Greetings,

Someone I work with has a macro problem and I'm trying to help out with it...hoping someone here can shed some light. He has a process set up in his Scheduler to open and Excel file every morning at 9:00 am. When it opens, the current macro triggers, adds a new worksheet, retrieves some information from an outside source, cleans up the data, and saves off the file. At that point he's wanting it to close the file AND the Excel window, because when it runs on his off days, the Excel window will not close following the macro, and the macro won't work the next time. So, there's the question. How do we get the Excel Window to close afterwards. He's said he's tried a bunch of different commands, but they don't work, especially after the file closes (which makes sense). I suggested a Personal Macro Workbook to hold the macro, but don't know if that would work or not, and we can't get it to close the window anyway. Here's the current code, if anyone can help with it. Thanks in advance.

Sub Auto_Open()
'
' Macro7 Macro
' Macro recorded 8/14/2007
'

'
Sheets.Add
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("A2").Select
ActiveWorkbook.XmlImport URL:=" ImportMap:= _
Nothing, Overwrite:=True, Destination:=Range("$A$2")
Selection.AutoFilter Field:=5, Criteria1:="<>0", Operator:=xlAnd
Range("E3:E115").Select
Selection.NumberFormat = "$#,##0.00"
Cells.Select
Cells.EntireColumn.AutoFit
Range("A123").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("G27").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("A1").Select

ActiveWorkbook.Save

ActiveWorkbook.Close
ActiveWindow.Close
End Sub
 
Code:
    ActiveWorkbook.Save
 [s]   
    ActiveWorkbook.Close
    ActiveWindow.Close[/s]
    application.quit
End Sub



_________________
Bob Rashkin
 
We'll try it. My buddy said he'd tried a lot of thing, but neither of us are VBA savvy, and don't know all of the commands. Thank you all for your help.

Scott
 
I think that what Bob is trying to say is this:

ActiveWorkbook.Save
ActiveWorkbook.Close
ActiveWindow.Close

Once you have closed the activeworkbook, you have also closed out the code that runs it.

Having ActiveWindow.Close afterward is redundant.

Everyone is correct in saying Application.Quit. If this does not work, try the below link. The article is called "50 Ways to Kill Excel".


I hope this helps.


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Application.quit worked great. Thanks again everyone for the assistance. One of these days I'm going to get a book for VBA and learn it!
Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top