"Reference is not valid" error when using analysis toolpak in an add-in

T

tom

aaarrrggghh, I keep getting an error the FIRST time that the following
line of code executes in an add-in I'm developing..

Application.Run "ATPVBAEN.XLA!Mcorrel", Range(Cells(1, 2), Cells(1,
2).End(xlToRight).End(xlDown)), Sheets("Matrix").Cells(1, 1), "C",
True

a box pops up saying "Reference is not valid", with an exclamation
icon.. the only option is "OK" then the correlation matrix is not
created..

the weird thing is, when I turn the file to not be an addin using
isaddin = false, the code works fine.. I've checked the ranges given
to it in the debugger with the watch window, and at the time the code
is executed they refer to the ranges I expect them to with the right
values in and so on..

the other weird thing, is I tried to recreate the error using a very
simple addin so I could try and work out what was going on, I
couldn't, but running the line of code in my test addin (with small
simple ranges) meant I stopped getting the error in my actual addin.

So I thought I'd put a dummy call to the Mcorrel procedure before the
one I neeeded as a workaround, the dummy call worked, then on the
actual call, I got the error again, BUT this time the matrix was
created correctly, so the code works now, but there is an annoying and
pointless dialog box that pops up in the middle all the time, its
doing my head in, I can't work out what is going on, and there is no
documentation on this error either in the application or on microsofts
support pages, its doing my head in. I can't get roiund it with excels
normal error handling, because it isn't an excel error, it seems to be
just a call to msgbox from within the analysis toolpak so theres no
way I can suppress it.

If anyone knows how I can fix this I'd be very grateful,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top