Save Changes to Add-In

M

MikeH2

I switched my personal.xls file to an add-in, .xla and when I exit Excel, I
am not prompted to save changes to the .xla file and sometimes, if I forget,
I lose changes. Is there a way to put something in the
"Workbook_BeforeClose" sub that will save the changes to the add-in?
 
C

Chip Pearson

In the ThisWorkbook module, use code like the following in the BeforeClose
event.

With Application
.EnableEvents = False
ThisWorkbook.Save
.EnableEvents = True
End With


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
M

MikeH2

Your solution did not seem to work but the one submitted before did:
With Application
.EnableEvents = False
ThisWorkbook.Save
.EnableEvents = True
End With

Not sure why but I hope this solves the problem.
 
D

Dave Peterson

You may want to add a prompt to Chip's suggested code.

If you're screwing around and delete multiple modules/routines, you may not want
to make it automatic.

Dim Resp as long
if me.saved = true then
'do nothing
else
resp = msgbox(Prompt:="Wanna save your changes?", buttons:=vbyesno)
if resp = vbyes then
With Application
.EnableEvents = False
me.Save 'me is ok, since the code is under the ThisWorkbook module
.EnableEvents = True
end with
end if
End With

(Untested, uncompiled--watch for typos.)

My personal preference is to not to do any development work in my personal.xla
file. I'll do all my testing in a separate workbook, then when I'm happy, I'll
move the code into my personal.xla. Then I'll just save manually.

I keep my personal.xla file marked readonly, too. Just to make it more
difficult for me to screw it up.
 
M

MikeH2

You final suggestion about doing testing elsewhere is probably the best
approach to this entire issue. That is what I'll do. Thanks!
 
D

Dave Peterson

And keep plenty of backups!
You final suggestion about doing testing elsewhere is probably the best
approach to this entire issue. That is what I'll do. Thanks!
 

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

Top