'Run-time error '-2147467261 (80004003) Object reference not set to an instance of an object

I'm getting the following error on the line 'ua' below. I'm trying to automate an Upsert to Salesforce through VBA using the enabler4excel object [automationObject].

Run-time error '-2147467261 (80004003)

Object reference not set to an instance of an object

Here is my code:

Dim addin As Office.COMAddIn
Dim automationObject As Object

For Each addin In Application.COMAddIns
    If addin.Description = "Enabler for Excel" Then
        Set automationObject = addin.Object
    End If
Next addin

Dim error
result = automationObject.LogIn(Username,Password,"https://test.salesforce.com", error)
If result = False Then
      MsgBox error
      End
End If

Range("b1").Select
Selection.End(xlDown).Select
bot_acc = ActiveCell.Row

Dim ExternalId As String
ExternalId = Range("A1")

Dim ObjectName As String
ObjectName = "Account"

Dim AccUpArray(13, 9999) As Variant

For Column = 0 To 12
    For Row = 0 To bot_acc - 2
        AccUpArray(Column, Row) = Worksheets("Account").Range("A2").Offset(Row, Column)
    Next Row
Next Column

ua = automationObject.UpsertData(AccUpArray, ObjectName, ExternalId, False, Nothing, error)
If Not error = Empty Then
     MsgBox error
     End
End If


Solution 1:[1]

I don't see where you dim ua but it is an object I assume (i.e. not an integer or string or boolean...) which means you need to use the keyword set

Set ua = automationObject.UpsertData(AccUpArray, ObjectName, ExternalId, False, Nothing, error)

Not seeing where you dim this could also mean you are not using Option Explicit. You should be.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community