We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Having problem with Excel automation from VB6

Last post 03-28-2008 2:51 PM by LukasPardal. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-13-2007 11:58 PM

    Having problem with Excel automation from VB6

    I am trying to call an excel subroutine that is in an add-in that is installed in excel.

    Severlal problems ... the first (and biggest) is that even though the add-in is installed, i keep getting errors that the add-in can't be found.  The call to the procedure is formatted like this:

    Sub ProcessXLFile(FilePath As String, _
        Repath As Boolean, _
        NewPath As String, _
        MakeFiles As Boolean, _
        CreateLog As Boolean, _
        LogFileName As String)

    Dim xlapp As Object
    Set xlapp = CreateObject("Excel.Application")

    Dim xlbook As Object
    Set xlbook = xlapp.Workbooks.Add

    Dim xlmodule As Object
    Set xlmodule = xlbook.vbproject.vbcomponents.Add(1)

    xlapp.Run ("haX2A.xla!PingRemoteTest")

    ...

     after this, I set the module to nothing and clean up normally.

    The add-in "haX2A.xla" is installed and is accessible (it has menu functions, toolbars available in Excel).  However, when the above code executes in a VB6 app, it opens the instance in Excel normally and I get an error message from Excel VBA that the file "haX2A.xla" could not be found.

     Once I get past that problem, I have the need to do more than a test function, obviously.  I need to be able to call a sub I have in "haX2A.xla" that will take arguments (I want to pass the arguments that this function in VB is being passed on to the VBA call to the add-in.  Anyone know how to call this in a VB run method for the xlapp as indicated above?

     I've searched far and wide for something on this and have come up empty.

     Thanks, Mac

    • Post Points: 10
  • 12-14-2007 3:34 PM In reply to

    • Uncle
    • Top 75 Contributor
    • Joined on 01-10-2002
    • Guru
    • Points 1,470

    Re: Having problem with Excel automation from VB6

    From the Microsoft knowledge base: 

    Add-ins do not load when using the CreateObject command in Excel

    http://support.microsoft.com/default.aspx?scid=kb;en-us;213489

    Symptoms: When you access Microsoft Excel as an OLE Automation object using the CreateObject command, add-ins, files that are located in the XLStart directory, and the default new workbook are not loaded.

    This article explains how to manually activate your addins.

     Hope this helps!

    • Post Points: 10
  • 12-16-2007 1:44 PM In reply to

    Re: Having problem with Excel automation from VB6

    I tried the method in the kb article and it didn't work.

    Because the add-in doesn't reside in XLStart, I have to set the path like this:

    xlapp.Workbooks.Open (haHome & "\" & "haX2A.xla")

    I recieve runtime error 1004 that "a document with the name 'haX2A.xla' is already open" ...

    If I comment out the "Workbooks.Open" statement, then I get an error 1004 that 'haX2A.xls' could not be found.

    This just makes no sense.

    I'm thinking that I may not be able to run a macro from XL in a .xla add-in.  I'm going to try building it in vba and adding as a component code module in a blank workbook at runtime and see if that works.  The problem is that I need to access routines in the xla at some point.

    Running VB6 SP6B, XL2003, XP Pro

    • Post Points: 10
  • 03-28-2008 2:51 PM In reply to

    • LukasPardal
    • Not Ranked
    • Joined on 03-28-2008
    • Czech Republic
    • New Member
    • Points 5

    Re: Having problem with Excel automation from VB6

    add to you script folowing  code, it opens all registered addins:

     

    'otevre vsechny zaregistrovany addiny
    For Each a In ExcApp.AddIns
       
        If a.Installed Then ExcApp.Workbooks.Open (a.FullName)

    Next

     

    My whole Code is:

    dim  ExcApp as object , a as object

    Set ExcApp = CreateObject("Excel.application")

    'opens new book

    ExcApp.Workbooks.Add
                   
                   
    ' open all registered addins

    For Each a In ExcApp.AddIns
       
        If a.Installed Then ExcApp.Workbooks.Open (a.FullName)

    Next
                   
                   
    ExcApp.Visible = True


    Set ExcApp = Nothing
     

     

    • Post Points: 5
Page 1 of 1 (4 items)