Closing workbooks

M

Mischa Browne

Hi



Struggling with the following problem.



Is it possible to close two workbooks working with VBA?



I have tried following codes:



Application.DisplayAlerts = False 'step 1
Windows("Book1.xls").Close 'step 2

Windows("Book2.xls").Close 'step 3
Application.DisplayAlerts = True 'step 4





Problem is, macro stops running after step 2!







Thanks,

Mischa
 
T

Tom Ogilvy

If you close the workbook that contains the macro, the macro stops. Close
the other workbook first

Workbooks("Book2.xls").Close SaveChanges:=Fasle
ThisWorkbook.Close SaveChanges:=False
 
A

anonymous

Dear Tom,

I have tried you solution.
Still does not work, note that the macro is in "Book3.xls".

Running the macro from "book3.xls" to close "book2.xls" and "book1.xls"
is this possible?


Tkx,
Mischa



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

Tom Ogilvy

Shouldn't be a problem

On Error goto 0
Application.EnableEvents = False
Workbooks("Book1.xls").Close SaveChanges:=False
Workbooks("Book2.xls").Close SaveChanges:=False
Application.EnableEvents = True
 
D

Don

Hi Mischa,

try this:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 6/17/2004 by Unknown User
'

'
Windows("Book1").Activate
ActiveWindow.Close
Windows("Book2").Activate
ActiveWindow.Close
End Sub

HTH....Don
 
Top