PDA

View Full Version : Solved: Can't get my XLA auto installer to work...



Dr.K
06-25-2007, 04:04 PM
This is driving me nuts...

I'm trying to set up an auto-installer for my XLA file. I'm basing it on the code listed in this article:
vbaexpress.com/forum/showthread.php?t=10855

Its two pieces, a data workbook as XLS and a macro workbook as XLA. I'll be distributing it as an XLS, so built into the workbook open event is a check for file extension... it is .XLS, it runs the AddInInstaller() sub.

Here is the relevant code:
Application.EnableEvents = False
AddIns.Add(AddInFname).Installed = True
Application.EnableEvents = True
Which produces this error:
Run-time error '1004':
Unable to get the Add property of the AddIns class

I've tried EVERYTHING! Using different forms of the file name, using different locations, using ThisworkBook.FullName, none of it works!
I also tried changing the code a little, to separate the steps:
Application.EnableEvents = False
AddIns.Add (AddInFname)
AddIns(AddInTitle).Installed = True
Application.EnableEvents = True
This produces a slightly different error:

Run-time error '1004':
Add method of Addins class failed

I even tried throwing out my code and pasting in the code from the article verbatim: same error, on the same piece of code.


AddIns.Add(ThisWorkbook.FullName, True) _
.Installed = True

Please help, I'm pulling my damn hair out.

johnske
06-25-2007, 04:23 PM
There are two possibilities - the relevant bit of the code is...


If Listed Then
'check this addins checkbox in the addin dialog box
AddIns(AddinTitle).Installed = True
Else
'it's not listed (not previously installed)
'add it to the addins collection
'and check this addins checkbox
AddIns.Add(ThisWorkbook.FullName, True) _
.Installed = True
End If


EDIT: Out of curiosity - this uses (http://xlvba.3.forumer.com/index.php?showtopic=266) the same code, do you have the same problem when installing it?

Dr.K
06-25-2007, 05:40 PM
Hey, alright! A response from the man who wrote the article!

Well, after beating my head against this for nearly 8 hours, I finally figured out the problem!!!

Excel cannot update the AddIns collection (either through the Excel Interface OR programmatically) UNLESS there is an open, visble workbook!
If there is no open, visible WB, it trying to add the AddIn throws the error.

It took me a ton of error trapping to figure that out.

My work around is this: add a dummy workbook at the begining of the install, and then close (false) near the end!

Finally, my macro works properly!

I'm WAY too bleary eyed to clean up all the code now, but tomorrow morning, I'll finnish all the code and post it here.

I'm surprised no one else has had this problem... maybe I've got something wierd in my settings?

johnske
06-25-2007, 05:48 PM
But did you have the same problem with the addin in the link I gave?

lucas
06-25-2007, 08:36 PM
The addin at your link installed ok for me John.

johnske
06-25-2007, 09:44 PM
The addin at your link installed ok for me John.Yes, I suspect Dr.K had modified it and that was what was causing the problem.

Thing is with this, is that when building that code, I was in contact with a couple of other coders (other boards) that were trying to do the same thing and we were all having various problems getting it to work properly.

Took a while but I saw that you had to be 1) methodical about it, as well as being methodical 2) the various operations all had to be done in a certain order (although there seemed no apparent reason why some couldn't be done in another order) but do them in another order and strange bugs appeared.

That's why I ended up making it generic code i.e. just paste in any workbook as is and run the code - there's only problems if you alter it :)

Dr.K
06-26-2007, 11:50 AM
Ok, so i figured it all out... you are correct, one line that I changed doomed me...

I combined the Reinstall/Install together: basically I added the lines to remove old code before installation. I wrapped them in a "On Error resume next" set of code, like I usually do when deleting files that may not be there.


'uninstall any previous versions
On Error Resume Next
Workbooks(RF_AI_FName & ".xla").Close False
AddIns(RF_AI_Title).Installed = False
Kill (Application.UserLibraryPath & RF_AI_FName & ".xla")
On Error GoTo 0


The line that caused all the problems : AddIns(RF_AI_Title).Installed = False
This line is totally unnecessary, the old AddIn is removed just fine by simply closing it and killing the file.

For whatever reason, having that line in there made the macro crash when it tried to .installed = true for the final AddIn install... UNLESS there is an open, visible workbook. Yes its true, I doubted it myself when I got up this morning, but I tested it pretty extensively. Adding and later removing a dummy workbook makes the code run fine.

So, I have two solutions:
1. Delete the unnecessary code line.
2. Add a few lines to add and remove a useless workbook.

I went with option 1. :)

Thanks for the help, guys.

srivakin
01-13-2022, 07:52 AM
Hello John,

By any chance can you please share the full code again. The link you have pasted is not valid anymore. Thanks

Paul_Hossler
01-14-2022, 05:53 AM
Unlikely, since Dr.K's last post was June 15, 2011

Bob Phillips
01-14-2022, 07:42 AM
There are plenty of free installers out there, I use InnoSetup.

Paul_Hossler
01-17-2022, 01:04 PM
There are plenty of free installers out there, I use InnoSetup.

I looked at that

Can it install a XLAM? I didn't see any way

Bob Phillips
01-17-2022, 04:04 PM
Yeah Paul, that is what I mainly use (used) it for.

You need to write some script to modify the registry, which is not a bit of chore, especially as it is Delhi as I recall, which is Pascal. I haven't done this in a while, but I am sure to have an example lying around that I can show you if interested.

Paul_Hossler
01-17-2022, 05:57 PM
Thanks -- I used to work in Delphi since I like(d) PASCAL for stand-alone applications, but for work reasons (before I retired) I ended up just using VBA to work within the MS Office suite


I do have a XLSM that saves itself as a XLAM, but it can be a little cumbersome, so I'd like to look at another example


If you don't mind searching for an example, I'll PM you my email address