Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Closing a workbook from a macro doesn't close the workbook

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Closing a workbook from a macro doesn't close the workbook

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Closing a workbook from a macro doesn't close the workbook


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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set macro to run automatically when closing workbook? Wuddus Excel Discussion (Misc queries) 10 January 20th 15 03:39 PM
Closing Excel with Personal Macro Workbook [email protected] Excel Discussion (Misc queries) 6 November 7th 07 11:07 PM
close workbook without closing excel and stop recursive function chris Excel Discussion (Misc queries) 3 July 10th 06 08:23 PM
Problem with closing workbook in macro slm Excel Programming 1 June 11th 05 01:23 AM
Problem closing a workbook using a macro Steve Excel Programming 3 September 21st 04 01:03 PM


All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"