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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving and closing all open Excel-files

Status
Not open for further replies.

mulderm

Technical User
Aug 13, 2006
3
NL
Hello,

I want to place vba-code in module1 to do all excel-files who is
open to save and to close.
I thought:

Sub test()
Dim ex As New Excel.Application
For Each w In ex.Workbooks
w.Close savechanges:=True
Next w
End Sub

but this is not working.
Any idea?

mulderm
 
and what about this ?
Sub test()
Dim ex As Object, w As Object
On Error Resume Next
Set ex = GetObject(, "Excel.Application")
If Err.Number = 0 Then
For Each w In ex.Workbooks
w.Close savechanges:=True
Next w
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank's PH, it's works excellent.

mulderm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top