Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Thanked 0 Times in 0 Posts

    COMAddIns Again (Excel 2002/r 1)

    I have created a COM Addin via te IDTExtensibity but setting it to load on startup. But in the Open event of the ThisWorkBook object of an Excel file, I am not able to create an instance of an object of my COMAddin. Here is the code:
    Dim oAddIn as Object
    Set oAddIn = Application.COMAddIns.Item("MyCOMAddIn.AddInDesign er1").Object
    At this point oAddIn is still equal to Nothing.

    I have alos tried the following
    Dim oAddIn as Object
    Set oAddIn = Application.COMAddIns("MyCOMAddIns.AddInDesigner1" )
    Now here it does set oAddin = "Microsoft Excel"

    Now when I attempt to call a function in the COM addin it fails. Example:
    where thefunction example is defined as publice function example(ByVal App as Application) as Boolean

    What am I doing wrong on these???

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Burwash, East Sussex, United Kingdom
    Thanked 229 Times in 210 Posts

    Re: COMAddIns Again (Excel 2002/r 1)

    Hi Jim,
    I'm not sure what you're trying to do with the ThisWorkbook_Open event. To call a function in your COM add-in, all you need to do is load the add-in. (Personally I would make the startup behaviour Load on Demand) Assuming your dll registered properly, you should see the functions listed if you use the Insert Function wizard-do they appear? You should also be able to check via the COM add-ins... menu option that your add-in is properly registered (you'll probably need to drag this onto your toolbar - right-click your toolbars, choose customize, on the commands tab choose Tools and the COM add-ins button should be listed about halfway down the list) - you should see the add-in and its load behaviour.
    I'm assuming that you have the usual Set oApp = application in the AddInInstance_OnConnection event in your add-in to establish the link to the current instance of Excel?
    Hope that helps.
    PS I'm also assuming that you're trying to call the function from Excel 2002 - if you need to support 2000 as well, you'll need to create an .xla wrapper for it.

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Springfield, Ohio, USA
    Thanked 2 Times in 2 Posts

    Re: COMAddIns Again (Excel 2002/r 1)

    In the ThisWorkbook open event, you want something like
    <pre> Application.COMAddIns("MyCOMAddIn.AddInDesigner1") .Connect = True</pre>

    I cannot tell you for sure what to put inside the quotes, it depends on your addin structure. If you record a macro of adding it manually through the COM Addins dialog box, you can see from the recording what goes in the quotes. HTH --Sam

    BTW, do you have a good reference book that you are following? Writing a COM Addin is very difficult. You should have:
    Microsoft Office 2000, Visual Basic for Applications Fundamentals, Microsoft Press
    Microsoft Office XP Developer's Guide, Microsoft Press
    Excel 2002 VBA, Programmer's Reference, Stephen Bullen et al, Wrox Press
    Don't let the "Fundamentals" in the first book fool you: it has the best COM tutorial.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts