Trouble calling Excel Data Analysis ToolPak functions from Access VBA

Rick Thackeray 0 Reputation points
2026-08-19T14:19:34.1433333+00:00

I am trying to run Excel's Data Analysis ToolPak functions from Access VBA, but I receive an error message: Application-Defined or Object-Defined error. Here is my code: objExcel.Run "ATPVBAEN.XLAM!Regress", objSheet.Range(rng_y), objSheet.Range(rng_x), objSheet.Range(rng_reg_out), True, True, 1, 0.95, True, True, False, False, False I start an instance of Excel with the CreateObject method in a Sub prior to the above line and pass a pointer to the function trying to access the toolpak.. The Excel created shows the Data Analysis ToolPak is loaded when checked under Options, but does not show on the Data toolbar ribbon. I have checked for the toolpak functions being loaded and they are. If I try doing the call against a fully qualified path to ATPBAEN.XLAM I get a message that effectively says I can't do that because of security considerations. If I start Excel from my taskbar shortcut, it shows the toolpak in the Data section. Any help would be greatly appreciated. Even if I could understand the differences in the way Excel is started, it would be helpful. Thank you. Rick

Microsoft 365 and Office | Access | For home | Windows

1 answer

Sort by: Most helpful
  1. Marcin Policht 106.8K Reputation points MVP Volunteer Moderator
    2026-08-19T15:23:43.9533333+00:00

    The likely issue is that CreateObject("Excel.Application") starts a separate Excel instance, and that instance does not necessarily load the Analysis ToolPak VBA add-in the same way as Excel started normally from the taskbar. Seeing the ToolPak enabled in Excel Options does not guarantee that ATPVBAEN.XLAM is loaded in your automation instance.

    Try loading the VBA add-in before calling Regress:

    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = True
    
    Dim ai As Object
    For Each ai In objExcel.AddIns
        If InStr(1, ai.Name, "Analysis ToolPak - VBA", vbTextCompare) > 0 Then
            ai.Installed = True
            Exit For
        End If
    Next
    

    Then use your existing call:

    objExcel.Run "ATPVBAEN.XLAM!Regress", _
        objSheet.Range(rng_y), objSheet.Range(rng_x), _
        objSheet.Range(rng_reg_out), True, True, 1, 0.95, _
        True, True, False, False, False
    

    Also verify that objSheet was created from the same objExcel instance. Do not use the full filesystem path to ATPVBAEN.XLAM; that can trigger Excel's security restrictions.

    The key difference is that Excel launched from the taskbar goes through the normal Excel startup process, while CreateObject creates a fresh automation instance with its own add-in state.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.