Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Workbooks.Close | Excel Programming | |||
workbooks close before | Excel Programming | |||
How to close All Workbooks | Excel Programming | |||
why do all excel worksheets/workbooks close when I close one? | Excel Discussion (Misc queries) | |||
close all other workbooks | Excel Programming |