View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Greg Lovern[_3_] Greg Lovern[_3_] is offline
external usenet poster
 
Posts: 5
Default MacroOptions doesn't stick

Thanks, but I'm not sure how knowing the hWnd and hInstance of the instance
I got with GetObject will help me get a different instance with GetObject.

I could use the Win32API to iterate through hWnds and identify the one or
ones I want, but even when I know which ones I want, I'm not sure how to do
a GetObject on those specific instances. As far as I can tell, GetObject
only ever returns the instance that was started first.

FunCustomize looks interesting. Since it does more than MacroOptions allows,
I guess he's doing it with the Win32 API rather than through VBA. I'll keep
that in mind for future reference, but I would have to take the time to
figure out how to do it myself rather than redistribute his DLL, and there
are higher priorities at the moment.

What I'm doing for now is checking the installed add-ins of the instance I
get with GetObject, and running the code only if my add-in is installed in
that instance. Worst case is that my functions end up in the User Defined
category, with no descriptions, and the user has to go to my function
reference helpfile to get more information.

Thanks,

Greg



"keepITcool" wrote in message
.com...


what version(s) of excel do your need to program for?

xlXP (and I think xl2000) expose their hWnd and hInstance
via the application object

also have a look at Laurent Longre's site.
his FunCustomize might be to your liking.
http://xcell05.free.fr/




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Greg Lovern wrote :

I found a way that works, but it seems like going the long way around
the barn. Surely there is an easier way than this?

Here's what I did:

Most of the code for my custom worksheet functions are in a VB6 DLL.
I put a timer on a form in the DLL. In the class_initialize event of
the class in the DLL that the Excel add-in instantiates, I enable the
timer and set its interval. In the timer event, I attempt to do a
GetObject on the running instance of Excel. If not successful, I keep
trying at each timer interval for a while before giving up. If the
Get_Object is ever successful, I use that to run the MacroOptions
code.

I'm still fully qualifying the function's address per keepITcool's
suggestion below.

It works fine, but if the user happens to have more than one instance
of Excel running, I might not get the right instance. Eventually I
may have to see if there is a way to iterate through all instances of
Excel. Also, if the user has a lot of startup stuff that takes a long
time to run, I'm not sure if it will prevent Get_Object from working.
I don't want it to keep trying forever.

Is there a more straightforward way to do it than this?