Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Close almost all workbooks

I've written some VBA code to open one workbook (call it "A") and in the open
event for workbook A I have it coded to open various other workbooks ("B",
"C", "D", etc).

I'm doing it this way so all the links are updated (one is password
protected and I can't give out the password so I've had to code opening them
in VBA and lock the VBA code).

I have everything I need except how to close workbooks B, C, D, etc. I don't
want to close all the workbooks as users may have other excel workbooks open
at the time. Any help is appreciated!

Thanks,
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Close almost all workbooks

You could use a for each workbook loop and then put an if statement in the
for each that says if the name is not "A" then close workbook.




ChrisP wrote:
I've written some VBA code to open one workbook (call it "A") and in the open
event for workbook A I have it coded to open various other workbooks ("B",
"C", "D", etc).

I'm doing it this way so all the links are updated (one is password
protected and I can't give out the password so I've had to code opening them
in VBA and lock the VBA code).

I have everything I need except how to close workbooks B, C, D, etc. I don't
want to close all the workbooks as users may have other excel workbooks open
at the time. Any help is appreciated!

Thanks,
Chris


--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Close almost all workbooks

Hi Chris

Look at this:

Set wbB = Workbooks.Open(Filename:="Book1.xls") ' Open "B"
'Your code
'More code
wbB.Close ' Close "B"

Hopes it helps

Best regards,
Per
"ChrisP" skrev i meddelelsen
...
I've written some VBA code to open one workbook (call it "A") and in the
open
event for workbook A I have it coded to open various other workbooks ("B",
"C", "D", etc).

I'm doing it this way so all the links are updated (one is password
protected and I can't give out the password so I've had to code opening
them
in VBA and lock the VBA code).

I have everything I need except how to close workbooks B, C, D, etc. I
don't
want to close all the workbooks as users may have other excel workbooks
open
at the time. Any help is appreciated!

Thanks,
Chris


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Close almost all workbooks

Thanks! One more question, workbooks B & C I don't want to save but D I do.
How would I write that?

Thanks again!
Chris

"Per Jessen" wrote:

Hi Chris

Look at this:

Set wbB = Workbooks.Open(Filename:="Book1.xls") ' Open "B"
'Your code
'More code
wbB.Close ' Close "B"

Hopes it helps

Best regards,
Per
"ChrisP" skrev i meddelelsen
...
I've written some VBA code to open one workbook (call it "A") and in the
open
event for workbook A I have it coded to open various other workbooks ("B",
"C", "D", etc).

I'm doing it this way so all the links are updated (one is password
protected and I can't give out the password so I've had to code opening
them
in VBA and lock the VBA code).

I have everything I need except how to close workbooks B, C, D, etc. I
don't
want to close all the workbooks as users may have other excel workbooks
open
at the time. Any help is appreciated!

Thanks,
Chris



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Close almost all workbooks

Try this code

Sub CloseWorkbooks()

Dim WB As Workbook

For Each WB In Application.Workbooks
If WB.Name < "A.xls" Then
If WB.Name = "D.xls" Then
WB.Close SaveChanges:=True
Else
WB.Close SaveChanges:=False
End If
End If
Next WB


End Sub



ChrisP wrote:
Thanks! One more question, workbooks B & C I don't want to save but D I do.
How would I write that?

Thanks again!
Chris

Hi Chris

[quoted text clipped - 27 lines]
Thanks,
Chris


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200808/1

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
Workbooks.Close andim Excel Programming 5 June 20th 08 06:18 PM
workbooks close before OlieH Excel Programming 1 April 6th 08 08:40 AM
How to close All Workbooks Mervyn Thomas Excel Programming 1 December 28th 07 09:22 PM
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
close all other workbooks Rob Excel Programming 5 February 5th 06 08:44 PM


All times are GMT +1. The time now is 08:44 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"