View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default addin running in different Excel instances

Just use a simple .ini file.

RBS

"Doug Glancy" wrote in message
...
Bob,

There are a couple of addin settings that are stored on a sheet.

Thanks,

Doug

"Bob Phillips" wrote in message
...
I have to ask, why are you saving the addin? It is against one of the
major principles of an addin IMO.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Doug Glancy" wrote in message
...
I have an addin that saves itself in either the BeforeClose of
AddinUninstall events. If for some reason I open multiple Excel
instances, when I close the one of the later instances the line
ThisWorkbook.Save saves the addin to the active Excel directory, e.g., My
Docs. No error is generated, it just saves a copy to the wrong place.

It's not a big problem if the addins in the multiple instances are not
saved. So instead of ThisWorkbook.Save I wrote code that uses
ThisWorkbook.Saveas and surrounded it with On Error statements and
turned of DisplayAlerts:

If Not ThisWorkbook.Saved Then
'in case it's read-only, which would be true if this were the 2nd (or
more) instance of Excel
On Error Resume Next
Application.DisplayAlerts = False
'I did SaveAs, because if it's read only Save will save to the active
Excel Directory
ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName
Application.DisplayAlerts = True
On Error GoTo 0
End If
Exit Sub
ErrorHandler:
Application.ScreenUpdating = True
Application.DisplayAlerts = True

This solution falls under the category of "crude but effective, I hope."
Does anybody have a better one?

XL03 Win Vista and XP

Thanks,

Doug