0

I'm having an issue with the Enabler for Excel in completing an Insert via VBA. I'm getting the following run-time error on the line listed below.

Line with error:

ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)

Error: Object reference not set to an instance of an object.

Here is my complete VBA code [option explicit]

Sub InsertOpportunityLineItem()
    Dim addin As Office.COMAddIn
    Dim automationObject As Object
    Dim bot_prod As Integer
    Dim column As Integer
    Dim error As String
    Dim ip As Variant
    Dim ObjectName As String
    Dim ProdInArray(10, 9999) As Variant
    Dim Result As Boolean
    Dim Row As Integer

    ObjectName = "OpportunityLineItem"

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

     'Login to environment
     Result = automationObject.LogIn(Username2, Password2, "https://test.salesforce.com", error)

     If Result = False Then
        MsgBox error
        End
     End If

    'build insert array
    For column = 0 To 10
          For Row = 0 To 19
                  ProdInArray(column, Row) = Worksheets(ObjectName).Range("B1").Offset(Row, column)
          Next Row
    Next column

    ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)
    If Not error = Empty Then
          MsgBox error
          End
    End If

    'write update results array
    For column = 0 To 1
         For Row = 0 To 18
               Worksheets(ObjectName).Range("R2").Offset(Row, column) = ip(column, Row)
         Next Row
    Next column

    Result = automationObject.LogOut()

End Sub
Brad
  • 11,934
  • 4
  • 45
  • 73
Amphitrite
  • 1
  • 1
  • 1
  • possible duplicate of [Run-time error '-2147467261 (80004003) Object reference not set to an instance of an object](http://stackoverflow.com/questions/23683973/run-time-error-2147467261-80004003-object-reference-not-set-to-an-instance-o) – Brad May 22 '14 at 16:17
  • Amphitrite, this was a bug in the add-on, did you try downloading a newer version? – taralex Aug 02 '14 at 20:54

2 Answers2

0

This kind of thing is always because you are setting the value of an object. Objects are reference type. Reference types need to use the keyword set. Do this to make the compiler happy.

set ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error) 
Brad
  • 11,934
  • 4
  • 45
  • 73
  • Thanks - I updated this and still getting the same error. It returns an array - is that still an object? – Amphitrite May 22 '14 at 16:49
  • Ah, I see. when you debug, is either `automationObject`, `ProdInArray`, or `ObjectName` null? – Brad May 22 '14 at 16:51
  • automationObject = SalesforceDLForExcel.AddInUtilities and ProdInArray is not empty and objectname is "Account" as expected. – Amphitrite May 22 '14 at 17:26
0

Amphitrite, it was a bug in the Enabler add-on. I think I fixed it around June this year.

taralex
  • 935
  • 2
  • 12
  • 29