Thank you Erich

I have just been reading about the AddIns collection and was wondering
whether to use that approach or not. Your reply has stopped me wondering
:-) and I will be adding your code to my project.

During my testing of the functions below, I found that they worked as
expected. That is, when RExcel2007 in the Add-ins list was checked, the
result was True, and when RExcel2007 in the Add-ins list was unchecked,
the result was False. 
However, I did a further test and got an unexpected result. I unchecked
RExcel2007 to uninstall it and then installed and ran my own add-in that
uses RExcel. I found that my own add-in worked and used R correctly.
This was unexpected. I had a assumed that if the RExcel add-in was
unchecked, then the RExcel functions would be unavailable. Is this
because I have added a reference to RExcelVBALib in the Tools >
Reference list? 

I am wondering about my user installing my add-in without RExcel being
present and, thereby, generating uncontrolled errors. I am wanting to
detect when the RExcel macros are available and when they are not so
that I can give a warning to the user when they try to do things that
require RExcel. Should I be doing this, do you think? Or, should I just
be making sure that I have RExcel properly installed before installing
my add-in (my defensive programming nerves start to twitch at the
thought!)?

Any thoughts on this would be appreciated.

Note: As a small modification, I added the line "Dim ai As AddIn" to
the code below so that does not give an error when "Option Explicit" is
used.

'Function code by Erich Neuwirth <[EMAIL PROTECTED]>
Function AddinInstalledAndEnabled(aiName As String) As Boolean
     Dim result As Boolean
     Dim ai As AddIn
     result = False
     For Each ai In Application.AddIns
         If ai.Name = aiName Then
             result = result Or ai.Installed
         End If
         If result Then Exit For
     Next ai
     AddinInstalledAndEnabled = result
End Function

'Function code by Erich Neuwirth <[EMAIL PROTECTED]>
Function RExcelAvailable() As Boolean
     RExcelAvailable = AddinInstalledAndEnabled("RExcel.xla") or _
                        AddinInstalledAndEnabled("RExcel2007.xlam")
End Function

Cheers, Andrew Mc


-- 

Andrew McLachlan, Biometrician
Crop & Food Research, Palmerston North, New Zealand.
Tel +64-6-356-8300,  +64-6-355-6110 (DDI)

>>> On 17/07/2008 at 8:06 p.m., Erich Neuwirth
<[EMAIL PROTECTED]>
wrote:
> Function AddinInstalledAndEnabled(aiName As String) As Boolean
>      Dim result As Boolean
>      result = False
>      For Each ai In Application.AddIns
>          If ai.Name = aiName Then
>              result = result Or ai.Installed
>          End If
>          If result Then Exit For
>      Next ai
>      AddinInstalledAndEnabled = result
> End Function
> 
> Function RExcelAvailable() As Boolean
>      RExcelAvailable = AddinInstalledAndEnabled("RExcel.xla") or _
>                         AddinInstalledAndEnabled("RExcel2007.xlam")
> End Function
> 
> 
> 
> 
> Andrew McLachlan wrote:
>> Hi All
>> 
>> Can anyone suggest to me ways of using VBA from within Excel to
detect
>> whether the RExcel add-in is installed or not?
>> My first thought is perhaps to check for the presence of some
RExcel
>> constants, for example, RExcelVersion.
>> 
>> Cheers, Andrew Mc
>> 
>> 
>> 
>> Visit our website at http://www.crop.cri.nz 
>> ______________________________________________________
>> CAUTION: The information contained in this email is privileged 
>> and confidential.  If you read this message and you are not the 
>> intended recipient, you are hereby notified that any use, 
>> dissemination, distribution or reproduction of all or part of the 
>> contents is prohibited. If you receive this message in error, 
>> please notify the sender immediately.
>> 
>> Any opinions or views expressed in this message are those of the 
>> individual sender and may not represent those of their employer.
>> 
>> _______________________________________________
>> Rcom-l mailing list
>> Rcom-l@mailman.csd.univie.ac.at 
>> http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l 
>> More information (including a Wiki) at http://rcom.univie.ac.at 
>> 
>> 


Visit our website at http://www.crop.cri.nz 
______________________________________________________
CAUTION: The information contained in this email is privileged 
and confidential.  If you read this message and you are not the 
intended recipient, you are hereby notified that any use, 
dissemination, distribution or reproduction of all or part of the 
contents is prohibited. If you receive this message in error, 
please notify the sender immediately.

Any opinions or views expressed in this message are those of the 
individual sender and may not represent those of their employer.

_______________________________________________
Rcom-l mailing list
Rcom-l@mailman.csd.univie.ac.at
http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
More information (including a Wiki) at http://rcom.univie.ac.at

Reply via email to