ThisWorkbook.close doesn't wokk :(

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H

I have a pb, I have created an Excel addin an I have put the following code in it
----------
Private Sub Workbook_BeforeClose(Cancel As Boolean
MsgBox ("Try to unload"
Application.ThisWorkbook.Close savechanges:=False 'or me.Clos
End Su
---------
I have name my file unloadtest.xl
if I double clic on this file from explorer, it works ok but if I create a shortcut who launch Excel with my file in parameters, it crashes
On excel 97 it does no crash but the unload of my xla fail
on Excel 2000 it crashe

Any Idea ? if it works for you could you tell me too plz

ThX By Advanc

Arnau
 
Hi Arnaud,

Thanks for posting in the community!

From my understanding, you have created one Excel xla add-in which will
capture the Workbook_BeforeClose event. If you double-click it, Excel works
very smoothly. However, if you start this from some startup switches, in
Excel 97, the xla can not be unloaded; in Excel 2000, this xla crashes.

In Excel 97, this is one known issue for the Workbook_BeforeClose event in
VBA. I'd suggest you can check the kb article for one workaround.
172749 XL97: Unable to Close File Activated by WorkbookBeforeClose
http://support.microsoft.com/?id=172749

In Excel 2000, since I don't know what Startup switches you used to start
Excel with the XLA add-in, I am not sure whether this event caused the
crash or something else. Moreover, I am also not sure whether you have
installed the latest office updates and patches for Office 2000 from
Office.Microsoft.com. If not, please go to the link to perform one
automatic update checking.
http://office.microsoft.com/search/redir.aspx?AssetID=ES790020331033&Origin=
HH011136791033&CTT=5

After that, if the issue remains no matter existing in 97 or 2000, I'd
suggest you can give me one detailed repro steps ( for 97 or 2000 or both )
with that add-in file ( or one simplified sample add-in which can crash
Excel2000 ) so that I can test this for you.

Look forward to your reply. Enjoy a nice weekend!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Tanks for your fast answer :
Yes You have well understood my problem :
But I don't use particular parameters, only the name of my xla file like this
"C:\Program Files\Microsoft Office 97\Office\EXCEL.EXE" "C:\MyLocalDucuments\UnloadAddins.xla
or
"C:\Program Files\Microsoft Office\Office\EXCEL.EXE" "C:\MyLocalDucuments\UnloadAddins.xla
depending where are my excel application and my addin located

I don't know how to send you the files then I will Email them to You
I have installed SP3 of Excel 2000 but the bug is still here

Step to reproduce my problem
Create an excel file renome it to .xla and set his isaddin property to true
insert this code in ThisWorkboo

---------------- start of code of code ---------------
Public closeLater As Boolea

Private Sub Workbook_BeforeClose(Cancel As Boolean
'set closeLater to false to call the close method no
'set closeLater to true to call the close method in 5 se

closeLater = Fals
MsgBox ("Try to auto-unload"

If (closeLater = False) The
Application.ThisWorkbook.Close savechanges:=Fals
Els
Application.OnTime Now + TimeValue("00:00:05"), "thisworkbook.KillLater
End I
End Su

Private Sub KillLater(
Application.ThisWorkbook.Close savechanges:=Fals
End Su
---------------- end of code ---------------

If I set closeLater to false then
--> crash in Excel 200
--> nothing happens in excel 9

If I set closeLater to true then
--> the adin is closed in 2000 like in 97 like I want but it is only a workaround
I don't want use this workaround because it can implies others bug and it is very dirty

Thx by advanc

arnau
 
Hi Arnaud,

Thank you for replying!

I have received your files. I am researching this issue for you. I will
post back when I have any result then.

Enjoy a nice weekend!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Arnaud,

Thank you for the detailed information about the repro!

From my view, you code will work very well for one workbook-scope workbook_beforeclose event. However, you are using them in one add-in
which has the application scope. This add-in can't locate which workbook to perform the operation even there is only one. This is the reason why
you get the crash or find some odd behavior. I'd suggest you can change the code from the original to the one below, adding one loop to search
the corresponding workbook and retrieve the information for your scenario:
'Code begin ----------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wbk As Workbook
For Each wbk In Application.Workbooks
'you can specify your own condition
' for example, you can also check your own CloseLater here.
If wbk.Saved = False Then
'perform some operations
....
'in sample, save the workbook directly
wbk.save
End If
Next
End Sub
'Code end ------------------------------------------------------

Please feel free to let me know if you have any further questions. I am standing by to be of assistance.

Have a nice day!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi

thanks for your answer, but it is not exactly what I want :
I have an addin in excel and a workbook scope
I modify the workbook scope and try to exit excel
The popup who ask me if I want to save apprears
Then I think ho my god no I don't want to quit !!
then I choose the cancel butto
My Workbook_BeforeClose event in the ADDIN has been called and the line thisworkbook.close (who is the addin) has been execute
Then the addin must have been unloaded !!
But it is not the case, my addin is still here !!

The problem in my true application (not the sample I have sent you) is that my addin has unloaded other addins but not himself !!! then when the user clic again on the .xla file, excel says himself: hey !!! I have already loaded this file nothing to do !!! and the addin that my main addin must launch are not loaded at all !!

Then My question is : how to do an addin who unload itself
Please launch the xla sample I have sent you to test and read the file "readfirst.txt" who explain how to reproduce step by step my problem, it take a very few times

Thx by advanc

Arnau

----- Wei-Dong Xu [MSFT] wrote: ----

Hi Arnaud

Thank you for the detailed information about the repro

From my view, you code will work very well for one workbook-scope workbook_beforeclose event. However, you are using them in one add-in
which has the application scope. This add-in can't locate which workbook to perform the operation even there is only one. This is the reason why
you get the crash or find some odd behavior. I'd suggest you can change the code from the original to the one below, adding one loop to search
the corresponding workbook and retrieve the information for your scenario
'Code begin ---------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean

Dim wbk As Workboo

For Each wbk In Application.Workbook
'you can specify your own conditio
' for example, you can also check your own CloseLater here

If wbk.Saved = False The
'perform some operation
...
'in sample, save the workbook directl

wbk.sav

End I

Nex
End Su
'Code end ------------------------------------------------------

Please feel free to let me know if you have any further questions. I am standing by to be of assistance.

Have a nice day

Wei-Dong X
Microsoft Product Support Service
Get Secure! - www.microsoft.com/securit
This posting is provided "AS IS" with no warranties, and confers no rights
 
Hi Arnaud,

Thank you for replying!

I have built one sample for you and sent it to you. If you haven't received it, please mail me or post one message in this thread. I will send you
again.

Best regards,

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi
Thx for your sample :
ok i I have well anderstood, there is truly a bug for an addin to close itself
And you propose to manage what excel must do with the loading and unloading of excel add-ins
- In your sample, you deal with addins installed in excel but how to deal with addin that are not integrated with excel
- If there are other addins loaded but not added to excel (not in list from tools->Add-Ins), how can I be sure to be called before others
- There is still a problem with the I18N and the dialog who display the message warning and the message. by sample in excel 2000 the message who ask to save or not modification in workbook is displayed in an asistant but in excel97 in a messagebox like yours
like you can see your hack is a good idea but there are some problem and maybe other that I don't know :(

Is there a patch or microsoft will do one for this bug

Thx Arnau
 
Hi Arnaud,

Thanks for the replying!

For the first question, I don't know in which scenario, the un-installed add-in will affect the excel execution.

For the second question, each COM add-in has its own registry setting for the startup type. This two kb article will introduce the difference between
the two types of add-in.
291392 INFO: Excel COM Add-ins and Automation Add-ins
http://support.microsoft.com/?id=291392

290868 HOWTO: Configure an Office COM Add-In for All Users on System
http://support.microsoft.com/?id=290868

For the third question, if the message is shown in the assistance window, I'd suggest you can disable the assistance.

Please feel free to let me know if you have any further questions. Enjoy a nice weekend!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Arnaud,


I am not quite understand this scenario. If one add-in is not installed into the Excel, it will affect the execution of Excel. It will be greatly appreciated
you tell me your concern on this. I am standing by to be of assistance.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Arnaud,


I am not quite understand this scenario. If one add-in is not installed into the Excel, it will not affect the execution of Excel. It will be greatly
appreciated you tell me your concern on this. I am standing by to be of assistance.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi
Sorry for the delay, I was in vacation :))

There are addin who can see from menu tools->addin like the autosave addin
But addin can be loaded in excel whithout appears in the addin displayed from this manu
If you create an addin and you dbl-click the xla file excel load himself and load also the addin
You can see it in vba projects, but not in the windows : "Add-Ins available:" from menu tools->addin

Bests regard

Arnaud
 
Hi Arnaud,

That's perfect alright!

If you double-click one xla add-in which is not installed in Excel, this add-in will not be installed. In this scenario, you can edit the xla add-in, not
install. You still need to install the add-in into Excel by placing the add-in in AddINs directory or load it from Tools->AddIns...

Please feel free to let me know if you have any further questions.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
hum no, if I click on an xla file (or if I use a shortcut of excel with my xla in parameter), the addin will be loaded in excel
But If I launch excel only, the addin will not be loaded
In fact the goal of it, is to keep excel in a normal way and if the user want use our application it adds functionalities like commandBar and toolbars
Then we don't want add addin in the excel list of addin

Arnaud
 
Hi Arnaud,

" if I click on an xla file (or if I use a shortcut of excel with my xla in parameter), the addin will be loaded in excel."

Yes, this is correct, as I have said in my reply above, in this way, you can edit the add-in, not load it into excel add-in manager.

"But If I launch excel only, the addin will not be loaded."

Since it hasn't been added into the add-in manager, of course, it will not be loaded.

"Then we don't want add addin in the excel list of addin."

Ok, if you don't want to add the xla manually, you can create one button in the xla workbook and install your add-in with automation. The kb article
280290 introduces this methods for you with sample code.
HOWTO: Install an Excel Add-In (XLA or XLL) with Automation
http://support.microsoft.com/id=280290

Please feel free to let me know if you have any further questions.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
nonono if you create an addin and launch it manually it will executes it. no need to add in the excel addin list

By sample in your addin :
------------- code start -------------------
Private Sub Workbook_Open(
MsgBox "my addin is loaded
End Su
------------- code end --------------------
 
Hi Arnaud,

When you double-click one xla, it will be opened by excel and run. You are correct!

However, as I have said, in this scenario, this xla is not installed by Excel. You can see this as one debug mode of xla. You can edit the xla code
directly. when you close excel then, you will not find this xla in the tools->add-ins... at the next startup.

Furthermore, if you dislike to install the add-in from Tools->Add-ins..., please try the method I suggeseted in my reply above.

Please feel free to let me know if you have any further questions.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi

Sorry I don't know where is the solution you have suggested
Do you do reference to this ?
"HOWTO: Install an Excel Add-In (XLA or XLL) with Automatio
http://support.microsoft.com/id=280290
first the page is not found and I know how to load an xla programaticaly from excel
My problem is just I can't unload myself in my xla because it crashes excel

Regard

Arnau


----- Wei-Dong XU [MSFT] wrote: ----

Hi Arnaud

When you double-click one xla, it will be opened by excel and run. You are correct!

However, as I have said, in this scenario, this xla is not installed by Excel. You can see this as one debug mode of xla. You can edit the xla code
directly. when you close excel then, you will not find this xla in the tools->add-ins... at the next startup.

Furthermore, if you dislike to install the add-in from Tools->Add-ins..., please try the method I suggeseted in my reply above.

Please feel free to let me know if you have any further questions

Best regards,
Wei-Dong X
Microsoft Product Support Service
Get Secure! - www.microsoft.com/securit
This posting is provided "AS IS" with no warranties, and confers no rights
 
Hi Arnaud,

I missed one "?" in the http link. Sorry for that! It should be:
http://support.microsoft.com/id=?280290

I know you meets the unload issue so I created one add-in for you to illustrate how to unload the add-ins. I'd suggest you'd better follow my sample
to unload your add-in. This way, there will be no exception thrown. If there is still something un-clear, we can divide this issue into three parts: Your
design for the add-in installation; its usage; its unload.

For each scenario, please let me know your concern. Then we can focus one each part to find one solution.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Wei-Dong

The correct URL was "http://support.microsoft.com/?id=280290" ;) not id=? but it's not important

I have look at your add-in you have sent me, but in your sample, you load/unload addin who are "installed" in Excel

In my sample I have sent you, no addin are loaded in it. The pb is only to unload the addin himself

If you have an idea, could you send me back my sample I had sent you with your modifications please

Thx a lo

Arnau

Ps : my addin sample was "UnloadAddins.xla" in the archive named "TestCloseAddin.zip

----- Wei-Dong XU [MSFT] wrote: ----

Hi Arnaud

I missed one "?" in the http link. Sorry for that! It should be
http://support.microsoft.com/id=?28029

I know you meets the unload issue so I created one add-in for you to illustrate how to unload the add-ins. I'd suggest you'd better follow my sample
to unload your add-in. This way, there will be no exception thrown. If there is still something un-clear, we can divide this issue into three parts: Your
design for the add-in installation; its usage; its unload.

For each scenario, please let me know your concern. Then we can focus one each part to find one solution.

Best Regards
Wei-Dong X
Microsoft Product Support Service
Get Secure! - www.microsoft.com/securit
This posting is provided "AS IS" with no warranties, and confers no rights
 

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

Back
Top