PC Review


Reply
Thread Tools Rate Thread

Closing a workbook from a macro doesn't close the workbook

 
 
=?Utf-8?B?RGF2ZSBQ?=
Guest
Posts: n/a
 
      9th Jul 2007
This is in Excel 2003.

From one workbook I want to open another workbook, copy some data out and
then close the other workbook.

The code is like this -

set wkb = workbooks("C:\BlahBlah\AnotherWorkbook,xls").open

<do some things that all work fine>

wkb.close

<go off and do something different>

When run in the VBA code window this works wonderfully well. Exactly as one
would expect.

When this sub is assigned to a ctrl key and run from the worksheet pane all
works as expected with the exception that the external workbook is left open.
I'm obviously missing something but I haven't a clue what.
Can anyone oblige?

Cheers,

Dave
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      10th Jul 2007
Dave, the only thing I can see is that you have Set the Wkb as an Object
variable with the open command incorporated. Maybe if you Set the variable
without the .Open command, then do Wkb.Open separately, it might close. I'm
just guessing since there doesn't seem to be anything wrong otherwise.

"Dave P" wrote:

> This is in Excel 2003.
>
> From one workbook I want to open another workbook, copy some data out and
> then close the other workbook.
>
> The code is like this -
>
> set wkb = workbooks("C:\BlahBlah\AnotherWorkbook,xls").open
>
> <do some things that all work fine>
>
> wkb.close
>
> <go off and do something different>
>
> When run in the VBA code window this works wonderfully well. Exactly as one
> would expect.
>
> When this sub is assigned to a ctrl key and run from the worksheet pane all
> works as expected with the exception that the external workbook is left open.
> I'm obviously missing something but I haven't a clue what.
> Can anyone oblige?
>
> Cheers,
>
> Dave

 
Reply With Quote
 
=?Utf-8?B?RGF2ZSBQ?=
Guest
Posts: n/a
 
      10th Jul 2007

Actually I can now answer my own question.

After I posted my original question here I went browsing for a couple of
hours. A vaguely related issue on opening workbooks gave me a hint.

The problem is not in the code at all. It lies with the definition of the
key to which the macro is attached : using a shifted value causes exactly the
behaviour I observed. I was using ctrl-shft-q and changing this to ctrl-q
fixed the problem. Simple when you know it.

This is apparently a bug in Excel.


Cheers,

Dave
 
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
closing a workbook with a macro Fan924 Microsoft Excel Programming 2 29th Nov 2008 03:57 AM
close workbook without closing excel and stop recursive function chris Microsoft Excel Misc 3 10th Jul 2006 08:23 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Microsoft Excel Programming 9 25th Jul 2005 12:44 PM
How to close active Workbook without closing other open workbooks? =?Utf-8?B?RnJhbWluZ2hhbTE=?= Microsoft Excel Misc 1 19th Oct 2004 12:59 AM
Re: Macro to run when closing off workbook ... Bob Phillips Microsoft Excel Misc 1 15th Jul 2003 10:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:50 AM.