Save Changes to Add-In

  • Thread starter Thread starter MikeH2
  • Start date Start date
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?
 
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)
 
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.
 
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.
 
You final suggestion about doing testing elsewhere is probably the best
approach to this entire issue. That is what I'll do. Thanks!
 
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!
 
Back
Top