0

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
Amphitrite
  • 1
  • 1
  • 1

1 Answers1

0

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.

Community
  • 1
  • 1
Brad
  • 11,934
  • 4
  • 45
  • 73
  • What would the dim look like? I'm not using Option Explicit because I couldn't figure this one out. – Amphitrite May 15 '14 at 17:14
  • @Amphitrite not using Option Explicit is what causes errors like this. – enderland May 15 '14 at 17:16
  • Now I'm getting an 'Object Required' error on this line - any ideas?: Dim result As Object Dim error Set result = automationObject.LogIn(Username, Password, "https://test.salesforce.com", error) If result = False Then MsgBox error End End If – Amphitrite May 15 '14 at 17:45
  • that looks like ti is several lines. You are `Dim`ing `result` and `error` but you `Dim` `error` as a variant and use it as a string later. you should Dim it as the appropriate data type. Ad you declare `result as Object` but test it for being `false`. Unless the object returned from the login method has a default property of boolean type you should probably declare `result as boolean` – Brad May 15 '14 at 17:56