SAP RFC Connection with VBA - BAD VARIANT TYPE

早过忘川 提交于 2020-01-06 07:05:32

问题


I'm having a problem with the SAP RFC when I'm trying to download some tables. When I try to create the connection I get the following error:

Bad Variant Type

I checked the regedit registry for RFC and it is all right.

The IT installed the SAP 7.50, but I'm unable to use such version cause it does not allow me to download some tables that I need, so I asked them to make the downgrade to the 7.40 version of SAP.

The problem started just there.

Public Sub conecta_sap()

Set ctlLogon = CreateObject("SAP.LogonControl.1")
Set funcControl = CreateObject("SAP.Functions")
Set ctlTableFactory = CreateObject("SAP.TableFactory.1")
Set objWindowsScriptShell = CreateObject("WScript.Shell")
Set objConnection = ctlLogon.NewConnection

objConnection.ApplicationServer = "XXXXXXXXXX"
objConnection.SystemNumber = "30"
objConnection.Client = "300"
objConnection.Language = "PT"
objConnection.USER = "RFC_LANCO"
objConnection.Password = "XXXXXXXX"
booReturn = objConnection.logon(0, True)

If booReturn <> True Then
    MsgBox "Impossível conectar no SAP!"
    End
End If

funcControl.Connection = objConnection
Set RFC_READ_TABLE = funcControl.Add("RFC_READ_TABLE")
Set strExport1 = RFC_READ_TABLE.exports("QUERY_TABLE")
Set strExport2 = RFC_READ_TABLE.exports("DELIMITER")
Set tblOptions = RFC_READ_TABLE.Tables("OPTIONS")
Set tblData = RFC_READ_TABLE.Tables("DATA")
Set tblFields = RFC_READ_TABLE.Tables("FIELDS")

End Sub

When I reach this line: funcControl.Connection = objConnection

I get the following error:

Erro em tempo de execução '-2147352568 (80020008)': Bad variant type

Can anyone help me solve this problem?

Thank you!

来源:https://stackoverflow.com/questions/56459823/sap-rfc-connection-with-vba-bad-variant-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!