Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default close workbooks before opening another workbook

I believe I may have asked this question before, but I can't seem to find the
question or a response to it. Here it is: I have a large Excel Workbook
that I want to have open first before opening two other files that link to
this one. I want to write a macro that will close any open workbooks when
this one is open. I tried an IF statement but my programming skills are
limited thus far and I don't think I wrote the correct code. Will someone
please help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default close workbooks before opening another workbook

Hi Rob,

Try:

'=============
Private Sub Workbook_Open()
Dim WB As Workbook

For Each WB In Application.Workbooks
If WB.Name < Me.Name Then
WB.Close SaveChanges:=True 'Or False?
End If
Next WB
End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module


---
Regards,
Norman


"Rob" wrote in message
...
I believe I may have asked this question before, but I can't seem to find
the
question or a response to it. Here it is: I have a large Excel Workbook
that I want to have open first before opening two other files that link to
this one. I want to write a macro that will close any open workbooks when
this one is open. I tried an IF statement but my programming skills are
limited thus far and I don't think I wrote the correct code. Will someone
please help?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close form automatically upon opening workbook Ixtreme Excel Discussion (Misc queries) 2 September 18th 09 02:56 PM
Update workbook links without opening all workbooks Steve Vincent Excel Discussion (Misc queries) 1 January 6th 09 11:14 PM
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
How to close specific workbook not all active workbooks? Bon Excel Programming 1 January 20th 06 02:49 PM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"