View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Problems checking for an Addin

Hi Trefor,

I haven't followed all this thread but have you tried -

Dim wbAddin As AddIn, wb as Workbook
'sTitle the workbook.title of your addin that you se in file properties

on error resume next
Set wbAddin = Application.AddIns(sTitle)

If not wbAddin is Nothing then

sPath = wbAddin.path
bInstalled = wbAddin.Installed ' ticked in addin manager

If it's not installed and not in one of the default addin paths it will not
be visible in Tools addins but a reference will exist in the registry.

Else
' is it loaded from file but not in the addin manager
set wb = application.workbooks("myAddin.xla")
sPath = wb.path

If the old addin is not in UserLibraryPath or LibraryPath, and it's in the
Addin's collection (whether or not installed) suggest install the updated
addin in the old path after uninstalling (if necessary) and removing the old
file. Otherwise the old addin's details will remain in the registry.

Regards,
Peter T


"Trefor" wrote in message
...
Tom,


Perhaps I should explain what I am trying to achieve:

I am distributing and Addin as a means of patching or fixing up code. So
this is what I do:


Check to see if the file in a directory is different to the one in
"Application.UserLibraryPath":

If Not FileMatch(DCMaster2, AppPath, Application.UserLibraryPath) Then


I then remove the Addin from Excel as I found I was getting Error = 70 on
the copy:

With AddIns.Add(FileName:=Application.UserLibraryPath & DCMaster2)
.Installed = False
End With


Then I copy the file from the directory to the Library:

FileCopy AppPath & "\" & DCMaster2, Application.UserLibraryPath &

DCMaster2


Then whether the above runs or not, I check to see if the addin is loaded

or
not:


WBName = Workbooks(DCMaster2).Name ?-Do I need to specify a path

here??
LastError = Err
On Error GoTo 0 ' restore error checking

If the Err =0 then I had presumed that the Addin had already loaded.
Otherwise it would need loading:

With AddIns.Add(FileName:=Application.UserLibraryPath & DCMaster2)
.Installed = False ? I added this line because if there had

been
a previous .Installed=True on the same file, but I had removed it for a
filecopy and I simply did a .Installed = True it would not load the file
because there was already a reference/link.
.Installed = True
End With
--
Trefor


"Tom Ogilvy" wrote:

Before you try to install it, you can always check for its existence

If dir(Application.UserLibraryPath & DCMaster2) = "" then
'Not in correct location

Also,

With AddIns.Add(FileName:=Application.UserLibraryPath &

DCMaster2)
.Installed = False
End With
With AddIns.Add(FileName:=Application.UserLibraryPath &

DCMaster2)
.Installed = True
End With


Seems flawed. Why install it twice.

Perhaps
With AddIns.Add(FileName:=Application.UserLibraryPath & DCMaster2)
.Installed = False
.Installed = True
End with

although I don't think the installed = False is necessary if it wasn't

in
the menu to begin with.

Nonetheless, I doubt that would account for your anomally. Checking if

the
file exists with Dir would seem the most straightforward.

--
Regards,
Tom Ogilvy



"Trefor" wrote:

Tom,

Thanks for the reply.

Public Const DCMaster = "'Customer Data Collect Master.xla'"

Dim DCMaster2 As String
DCMaster2 = Replace(DCMaster, "'", "")

--
Trefor


"Tom Ogilvy" wrote:

is DCMaster of the form Myaddin.xla or just MyAddin

If the latter, then always use the extension.

--
Regards,
Tom Ogilvy


"Trefor" wrote:

I use the below code to check for an AddIn, the problem I have is

the line
marked * sometimes causes an if the file is missing, but sometime

the error
code is ZERO, even though the file is not installed.

I have not quite worked out what is going on, but this line seems

to be
inconsistant in its result.


Dim WBName As String
On Error Resume Next ' turn off error checking
* WBName = Workbooks(DCMaster2).Name
LastError = Err
On Error GoTo 0 ' restore error checking
If LastError < 0 Then
' the add-in workbook isn't currently open. Manually open it.
On Error Resume Next
Application.DisplayAlerts = False
With AddIns.Add(FileName:=Application.UserLibraryPath &

DCMaster2)
.Installed = False
End With
With AddIns.Add(FileName:=Application.UserLibraryPath &

DCMaster2)
.Installed = True
End With
Application.DisplayAlerts = True
LastError = Err
On Error GoTo 0 ' restore error checking
If LastError < 0 Then
' The workbook was not found in the correct location
AddinPresent = False
Else
' The workbook was found and installed
AddinPresent = True
End If
Else
' No error so the workbook is already loaded
AddinPresent = True
End If
End Function



--
Trefor