ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing workbooks (https://www.excelbanter.com/excel-programming/301716-closing-workbooks.html)

Mischa Browne

Closing workbooks
 
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







Tom Ogilvy

Closing workbooks
 
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

--
Regards,
Tom Ogilvy

"Mischa Browne" wrote in message
...
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









anonymous

Closing workbooks
 
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!

Tom Ogilvy

Closing workbooks
 
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

--
Regards,
Tom Ogilvy


"anonymous" wrote in message
...
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!




Don

Closing workbooks
 
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

"anonymous" wrote:

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!



All times are GMT +1. The time now is 12:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com