Close a workbook

S

Simon

Hi
When closing one workbook I want it to close another.
I have tried
Workbooks("C:XXX\BOOK1.XLS").Close SaveChanges:=False

Which doesnt seem to work.
Without making the other workbook active is there any other way to close it?

Many thanks
Simon
 
H

Harald Staff

Hi Simon

"C:XXX\BOOK1.XLS" is probably not a valid path. Maybe you do not need a
path.

HTH. Best wishes Harald
 
S

Simon

Sorry,
Forgot to mention that I also need code to check whether the workbook is
actually open.
I am using v2007
 
D

Dave Peterson

Once the workbook is open, excel doesn't need or want that drive and path.

Try:

Workbooks("BOOK1.XLS").Close SaveChanges:=False

In fact, you may want to open it nicely, too:

Dim wkbk as workbook
set wkbk = workbooks(filename:="c:\xxx\book1.xls")
'do lots of stuff
wkbk.close savechanges:=false

When you're opening the file, you'll want to tell excel where to look -- not
just rely on the current directory.
 
D

Dave Peterson

I'd just ignore any error:

on error resume next
workbooks("book1.xls").close savechanges:=false
 

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

Top