PDA

View Full Version : Solved: Save changes to Add-in on application close



gabethegrape
05-20-2009, 10:18 PM
I have an add-in with content that can be modified via a userform. The problem is, the changes aren't being saved. How can I save the add-in whenever Excel closes? Thanks very much,
Gabe

Aussiebear
05-21-2009, 12:16 AM
A quick search of the net comes up with this answer;

http://www.bettersolutions.com/excel/ECA723/VU822216331.htm.

Saving your changes.

When you make changes to a workbook and try and close it, you are prompted to save your changes.

If you make any changes to your code in an Excel add-in, you will not be prompted to save the changes. You must manually save the changes before closing.

Bob Phillips
05-21-2009, 01:23 AM
You should not use the addin to persist your data, you should use some other method, such as a textfile, an INI file, the registry and so on.

anandbohra
05-21-2009, 01:41 AM
I have an add-in with content that can be modified via a userform. The problem is, the changes aren't being saved. How can I save the add-in whenever Excel closes? Thanks very much,
Gabe

Write this code in Thisworkbook of your Addin
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub

gabethegrape
05-21-2009, 09:45 AM
Thanks for the reply. That works well. XLD, how would I go about saving my data to a text file? What's the advantage of doing it this way over saving the changes directly in the add-in? I noticed when I added the code to save the add-in before close that excel stalls a bit. Is this one of the disadvantages? Would it do this if I stored the data in a text file or an INI?

Bob Phillips
05-21-2009, 11:08 AM
It is not a good practice to keep the data and the logic in the same workbook, it creates unnecessary complexities. Far better to separate them, so that the logic goes in the addin, and the data goes in some sort of data repository, whatever you choose for trhat.