PC Review


Reply
Thread Tools Rate Thread

Closing FIle with Command Bar Button Problem

 
 
JeffTO
Guest
Posts: n/a
 
      7th Dec 2009
Hi All

I posted this last week with a different title and didnt get any
responses - so perhaps my messages was not understood - so I am trying
again:

I am getting a very strange error which I have isolated but I do not
know how to get rid of:

I have a workbook with the following code:

Sub MYexit()
ThisWorkbook.Saved = True
ThisWorkbook.Close
End Sub


When I run the macro directly from the macro with other workbooks open
or closed there is no problem


However...


When I create a toolbar with a single button and assign MYExit to the
button - I get an "Application-defined or object-defined error" ONLY
if other workbooks are open - I do not get this message if there are
no other workbooks open.

So it looks like the problem is being cause by running the macro with
a command button when other workbooks are open - again there is no
code causing this error - I step through all the code no problem and
this error comes up after all the code runs properly - so I am not
sure how to trap it so I can avoid the error message being shown.


Any thoughts would be great

I really appreciate any ideas on this one

Thanks,

Jeff
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      7th Dec 2009
Change the OnAction from MYexit to OnTimeExit

Sub OnTimeExit()
Application.OnTime Now, "MYexit"
End Sub

In passing, you could do simply
ThisWorkbook.Close False

Trust your close event code destroys the toolbar (and creates it again in
the open event)

Regards,
Peter T


"JeffTO" <(E-Mail Removed)> wrote in message
news:bb18bf9e-261a-4cbb-a374-(E-Mail Removed)...
> Hi All
>
> I posted this last week with a different title and didnt get any
> responses - so perhaps my messages was not understood - so I am trying
> again:
>
> I am getting a very strange error which I have isolated but I do not
> know how to get rid of:
>
> I have a workbook with the following code:
>
> Sub MYexit()
> ThisWorkbook.Saved = True
> ThisWorkbook.Close
> End Sub
>
>
> When I run the macro directly from the macro with other workbooks open
> or closed there is no problem
>
>
> However...
>
>
> When I create a toolbar with a single button and assign MYExit to the
> button - I get an "Application-defined or object-defined error" ONLY
> if other workbooks are open - I do not get this message if there are
> no other workbooks open.
>
> So it looks like the problem is being cause by running the macro with
> a command button when other workbooks are open - again there is no
> code causing this error - I step through all the code no problem and
> this error comes up after all the code runs properly - so I am not
> sure how to trap it so I can avoid the error message being shown.
>
>
> Any thoughts would be great
>
> I really appreciate any ideas on this one
>
> Thanks,
>
> Jeff



 
Reply With Quote
 
JeffTO
Guest
Posts: n/a
 
      7th Dec 2009
Hi Peter

Works perfectly - thank you soooo much

And yes I do create the toolbar on open and delete on close

The actual live code is more complex than the sample I gave but the
problem was the same - so now that I have it working in the sample - I
am going to implement in my live code

Can you tell me why yours works and mine didnt? I am curious to know
what the difference is.

Thanks again - exteremely helpful

Jeff
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Dec 2009
Hmm .... good question ... don't know!

I'm almost sure for a while all was working fine if I added the parameter
Temporary:=True to commandbars.add(). But now that doesn't help.

At the moment I can't say why it fails with no other visible workbooks, but
the reason the OnTime fixes is because the close code is not being called
from the button.

(btw the issue is if there are/not other *visible* workbooks)

Regards,
Peter T

"JeffTO" <(E-Mail Removed)> wrote in message
news:8927e0d3-54fb-424e-a1b6-(E-Mail Removed)...
> Hi Peter
>
> Works perfectly - thank you soooo much
>
> And yes I do create the toolbar on open and delete on close
>
> The actual live code is more complex than the sample I gave but the
> problem was the same - so now that I have it working in the sample - I
> am going to implement in my live code
>
> Can you tell me why yours works and mine didnt? I am curious to know
> what the difference is.
>
> Thanks again - exteremely helpful
>
> Jeff



 
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 an Excel Spreadsheet via command button bartlwf@aol.com Microsoft Excel Programming 1 15th Feb 2008 04:45 PM
closing my application throught my command button =?Utf-8?B?cm9jY28=?= Microsoft Access VBA Modules 3 18th Jun 2006 09:01 PM
Problem with closing a form using a command button John S. Ford, MD Microsoft Access Forms 2 3rd May 2006 02:09 PM
Problem with closing a form using a command button John S. Ford, MD Microsoft Access Form Coding 2 3rd May 2006 02:09 PM
Command Button for closing form A Hewitt Microsoft Access Form Coding 1 10th Dec 2003 12:00 PM


Features
 

Advertising
 

Newsgroups
 


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