Close specific excel files

camg12

Registered User.
Local time
Today, 13:09
Joined
Jan 5, 2010
Messages
18
I run a sub routine to open four different excel files. I need another sub routine to close the four specific excel files? Here is the code I am using to open and save.

Private Sub CmdOpenExcel()
'Opens the specified Spreadsheet
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = New Excel.Application
With xlApp
.Visible = True
Set xlWB = .Workbooks.Open("C:\Book1.xlsx", , False)
xlApp.ActiveWorkbook.Save
Set xlWB = .Workbooks.Open("C:\Book2.xlsx", , False)
xlApp.ActiveWorkbook.Save
Set xlWB = .Workbooks.Open("C:\Book3.xlsx", , False)
xlApp.ActiveWorkbook.Save
Set xlWB = .Workbooks.Open("C:\Book4.xlsx", , False)
xlApp.ActiveWorkbook.Save
End With
End Sub
 
Code:
xlApp.Application.ActiveWorkbook.Close

Ensure your are closing everying related to the objects in your code...

Code:
    Set xlApp = Nothing
    Set xlSheet = Nothing
...etc
 

Users who are viewing this thread

Back
Top Bottom