‎2007 Aug 23 3:18 AM
Can anyone let me know the reasons why method connection fails in VBA excel macro?
Logic used so far in excel VBA:
1) Create SAP connection
2) Connect to BAPI ( this is a custom bapi created and released in BOR)
3) Populate the method parameters
4) Pass the parameters to the method (<b>this is where it fails in the dev envi but works fine in sandbox</b>)
5) logoff bapi
any feedback would be a lot of help.
thanks
Kshamatha
‎2007 Aug 23 2:02 PM
I had tried to call RFC FMs from Excel - here is some sample code - might be helpful for u-
Sub Get_Report_List()
Dim SAPFunCtl As New SAPFunctions
Dim RFCFunc As New SAPFunctionsOCX.Function
Dim I_QUERY_TABLE
Dim T_OPTIONS
Dim T_FIELDS
Dim T_DATA
Dim Row As Integer
'Pop up for Automatic Logon.
SAPFunCtl.AutoLogon = True
'Set the Function Module to be called
Set RFCFunc = SAPFunCtl.Add("RFC_READ_TABLE")
'Set the Import, Export & Table Parameters
Set I_QUERY_TABLE = RFCFunc.Exports("QUERY_TABLE")
Set T_OPTIONS = RFCFunc.Tables("OPTIONS")
Set T_FIELDS = RFCFunc.Tables("FIELDS")
Set T_DATA = RFCFunc.Tables("DATA")
'Query Table TRDIR
I_QUERY_TABLE.Value = "TRDIR"
T_OPTIONS.AppendRow
T_OPTIONS(1, "TEXT") = "NAME LIKE 'Z%'"
T_FIELDS.AppendRow
T_FIELDS(1, "FIELDNAME") = "NAME"
T_FIELDS.AppendRow
T_FIELDS(2, "FIELDNAME") = "SUBC"
If RFCFunc.Call = True Then
If T_DATA.RowCount > 0 Then
'Clear Sheet3 - Data
Sheet3.Cells.Clear
For Row = 1 To T_DATA.RowCount
Sheet3.Cells(Row, 1) = T_DATA(Row, "WA")
Next Row
Sheet3.Activate
End If
Else
MsgBox "Connection failure."
End If
End Sub
‎2007 Aug 23 11:48 PM