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