ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   preventing addIn opening in second instance of Excel? (https://www.excelbanter.com/excel-programming/386916-preventing-addin-opening-second-instance-excel.html)

Matthew Dodds

preventing addIn opening in second instance of Excel?
 
I have an AddIn into which are written a few small details before
close (I know this isn't great practice but it saves me having to
setup a log file external to the AddIn and the attendant risk that
this will be deleted)

When a second instance of excel is opened it opens the AddIn as read-
only. On shut down this prevents the few small details being written
back to it and the user is prompted to save a copy of the AddIn
elsewhere. Undesirable

Two solutions come to mind (beyond setting up a remote log file) but I
don't know how to effect either
1. prevent the second instance of excel from opening the AddIn
(preferable)
2. prevent the addin from working in the second instance, hence not
generating the few small details and not being able to save them

How can I get the second instance of excel NOT to load the addin?
Thanks in advance ... and thanks to all for all the databased
contributions here ... if this group wasn't here I'd still be spending
all afternoon charting data instead of doing it at the touch of a
button!
Matthew


Peter T

preventing addIn opening in second instance of Excel?
 
In an open event -

If Thisworkbook.Readonly then
Thisworkbook.close
End if

Or, abort any routines you don't want to process
If ThisWorbook.Readonly then Exit Sub
perhaps assign .ReadOnly to a global boolean

In theory it might be possible to change the registry setting for installed
addins in the addin's open event if the addin is not readonly, then reset in
the close. Would prevent the addin opening in further instances but a bit
risky.

Why not store your store your 'few small details' in the registry, look into
SaveSetting and the See also's in help.

Regards,
Peter T



"Matthew Dodds" wrote in message
oups.com...
I have an AddIn into which are written a few small details before
close (I know this isn't great practice but it saves me having to
setup a log file external to the AddIn and the attendant risk that
this will be deleted)

When a second instance of excel is opened it opens the AddIn as read-
only. On shut down this prevents the few small details being written
back to it and the user is prompted to save a copy of the AddIn
elsewhere. Undesirable

Two solutions come to mind (beyond setting up a remote log file) but I
don't know how to effect either
1. prevent the second instance of excel from opening the AddIn
(preferable)
2. prevent the addin from working in the second instance, hence not
generating the few small details and not being able to save them

How can I get the second instance of excel NOT to load the addin?
Thanks in advance ... and thanks to all for all the databased
contributions here ... if this group wasn't here I'd still be spending
all afternoon charting data instead of doing it at the touch of a
button!
Matthew




Matthew Dodds

preventing addIn opening in second instance of Excel?
 
Thanks Peter, that works.

You suggest aborting routines I don't want to process. If these
routines are spawned by a commercial AddIn to which I have no access,
how could I recognise these processes in code (I know only the AddIn's
VBAProjectName and fileName)

As for writing the 'few small details' into registry I've always
thought writing into registry was somehow risky (??) Shoudl I thinhk
otherwise about it? Horrow stories about risks to machine integrity
down to hamfisted users rather than cautious amateur VBA hacks?)

Thanks

Matthew


On 5 Apr, 23:01, "Peter T" <peter_t@discussions wrote:
In an open event -

If Thisworkbook.Readonly then
Thisworkbook.close
End if

Or, abort any routines you don't want to process
If ThisWorbook.Readonly then Exit Sub
perhaps assign .ReadOnly to a global boolean

In theory it might be possible to change the registry setting for installed
addins in the addin's open event if the addin is not readonly, then reset in
the close. Would prevent the addin opening in further instances but a bit
risky.

Why not store your store your 'few small details' in the registry, look into
SaveSetting and the See also's in help.

Regards,
Peter T

"Matthew Dodds" wrote in message

oups.com...



I have an AddIn into which are written a few small details before
close (I know this isn't great practice but it saves me having to
setup a log file external to the AddIn and the attendant risk that
this will be deleted)


When a second instance of excel is opened it opens the AddIn as read-
only. On shut down this prevents the few small details being written
back to it and the user is prompted to save a copy of the AddIn
elsewhere. Undesirable


Two solutions come to mind (beyond setting up a remote log file) but I
don't know how to effect either
1. prevent the second instance of excel from opening the AddIn
(preferable)
2. prevent the addin from working in the second instance, hence not
generating the few small details and not being able to save them


How can I get the second instance of excel NOT to load the addin?
Thanks in advance ... and thanks to all for all the databased
contributions here ... if this group wasn't here I'd still be spending
all afternoon charting data instead of doing it at the touch of a
button!
Matthew- Hide quoted text -


- Show quoted text -




Peter T

preventing addIn opening in second instance of Excel?
 
Could the problem you described with your own addin also occur with any
third party, commercial or otherwise? I wouldn't have thought so, but if
really necessary you could write your own code to unload these if they are
ReadOnly.

If you use VBA's SaveSetting, and related functions, there shouldn't be any
risk at all. The absolute worst that could happen is access (permissions) is
blocked by the administrator though unlikely in that particular area of the
registry (not entirely sure about Vista though also no damage).

A small thing to be aware of writing is something like "my addin is
currently loaded in Excel". If your app closes unexpectedly before clearing
the setting it might be there for all time as a false positive.

Regards,
Peter T


"Matthew Dodds" wrote in message
oups.com...
Thanks Peter, that works.

You suggest aborting routines I don't want to process. If these
routines are spawned by a commercial AddIn to which I have no access,
how could I recognise these processes in code (I know only the AddIn's
VBAProjectName and fileName)

As for writing the 'few small details' into registry I've always
thought writing into registry was somehow risky (??) Shoudl I thinhk
otherwise about it? Horrow stories about risks to machine integrity
down to hamfisted users rather than cautious amateur VBA hacks?)

Thanks

Matthew


On 5 Apr, 23:01, "Peter T" <peter_t@discussions wrote:
In an open event -

If Thisworkbook.Readonly then
Thisworkbook.close
End if

Or, abort any routines you don't want to process
If ThisWorbook.Readonly then Exit Sub
perhaps assign .ReadOnly to a global boolean

In theory it might be possible to change the registry setting for

installed
addins in the addin's open event if the addin is not readonly, then

reset in
the close. Would prevent the addin opening in further instances but a

bit
risky.

Why not store your store your 'few small details' in the registry, look

into
SaveSetting and the See also's in help.

Regards,
Peter T

"Matthew Dodds" wrote in message

oups.com...



I have an AddIn into which are written a few small details before
close (I know this isn't great practice but it saves me having to
setup a log file external to the AddIn and the attendant risk that
this will be deleted)


When a second instance of excel is opened it opens the AddIn as read-
only. On shut down this prevents the few small details being written
back to it and the user is prompted to save a copy of the AddIn
elsewhere. Undesirable


Two solutions come to mind (beyond setting up a remote log file) but I
don't know how to effect either
1. prevent the second instance of excel from opening the AddIn
(preferable)
2. prevent the addin from working in the second instance, hence not
generating the few small details and not being able to save them


How can I get the second instance of excel NOT to load the addin?
Thanks in advance ... and thanks to all for all the databased
contributions here ... if this group wasn't here I'd still be spending
all afternoon charting data instead of doing it at the touch of a
button!
Matthew- Hide quoted text -


- Show quoted text -







All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com