PC Review


Reply
Thread Tools Rate Thread

Close a workbook

 
 
Simon
Guest
Posts: n/a
 
      12th Apr 2010
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
 
Reply With Quote
 
 
 
 
Harald Staff
Guest
Posts: n/a
 
      12th Apr 2010
Hi Simon

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

HTH. Best wishes Harald

"Simon" <(E-Mail Removed)> wrote in message
news:71918F50-2338-44F8-9EAF-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      12th Apr 2010
Sorry,
Forgot to mention that I also need code to check whether the workbook is
actually open.
I am using v2007

"Simon" wrote:

> 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

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Apr 2010
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.

Simon wrote:
>
> 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


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Apr 2010
I'd just ignore any error:

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



Simon wrote:
>
> Sorry,
> Forgot to mention that I also need code to check whether the workbook is
> actually open.
> I am using v2007
>
> "Simon" wrote:
>
> > 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


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
error in running workbook.close() func. after close excel from win Kayıhan Microsoft C# .NET 0 29th Mar 2009 12:49 AM
Close a Excel Workbook when close a userform in Outlook lars.oyangen@hamstad.no Microsoft Outlook VBA Programming 2 8th May 2008 02:54 PM
Open New Workbook / Save and Close Current Workbook Joe K. Microsoft Excel Programming 1 7th Dec 2007 08:04 PM
Closing a workbook from a macro doesn't close the workbook =?Utf-8?B?RGF2ZSBQ?= Microsoft Excel Programming 2 10th Jul 2007 06:16 PM
Excel 2000 Workbook close button hides instead of close Steven Robinson Microsoft Excel Misc 3 13th Aug 2003 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:37 PM.