vba 运行时错误 '-2147467261 (80004003) 未将对象引用设置为对象的实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23683973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run-time error '-2147467261 (80004003) Object reference not set to an instance of an object
提问by Amphitrite
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].
我在下面的“ua”行中收到以下错误。我正在尝试使用 enabler4excel 对象 [automationObject] 通过 VBA 将 Upsert 自动化到 Salesforce。
Run-time error '-2147467261 (80004003)
运行时错误'-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
回答by Brad
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
我没有看到你在哪里变暗,ua
但它是我假设的一个对象(即不是整数、字符串或布尔值......)这意味着你需要使用关键字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.
没有看到您调暗的位置也可能意味着您没有使用Option Explicit
. 你应该是。