Close other open excel files

  • Thread starter Thread starter anon
  • Start date Start date
A

anon

HI,

I'd like my wb on opening to close all other excel files that are open
(prompting them to save first).

I'd also like to prevent the user opening any other excel files whilst
my wb is open.

Is this possible (and is it a stupid thing to try and do?)
 
Easy

for each wbk in workbooks
if wbk.name <> ThisWorkbook.name then
workbooks(wbk.name).close
end if
next wbk
 
How can i modify this to prevent thisworkbook.name and another excel file not
to close? I need the files "Daily Reports.xls" and "NPP_*" to stay open.
Thanks
 
for each wbk in workbooks
if wbk.name = ThisWorkbook.name then
'do nothing
elseif lcase(wbk.name) = lcase("daily report.xls") then
'skip this, too
elseif lcase(left(wbk.name,4))= lcase("npp_") then
'skip more!
else
wbk.close savechanges:=false 'or true????
end if
next wbk
 
Sub test()

For Each wbk In Workbooks
If wbk.Name <> ThisWorkbook.Name And _
wbk.Name <> "Daily Reports.xls" And _
Left(wbk.Name, 4) <> "NPP_" Then

Workbooks(wbk.Name).Close
End If
Next wbk

End Sub
 
test
Greg H. said:
How can i modify this to prevent thisworkbook.name and another excel file
not
to close? I need the files "Daily Reports.xls" and "NPP_*" to stay open.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top