Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Calling RFC (remote enabled function module) through excel VBA in sap

Hi Team,

I need to call Remote function module through excel for data validation on click of command button.

I am getting errors such as "user defined type not defined" for SAPFunctionsOCX.SAPFunctions.

Can anybody help me in this? Or is there any complete docuement for this procedure to call RFC through excel VBA?

Thanks,

Sanjana

Tags:
Former Member replied

Hi,

Please find sample VB script code and make changes as per needed.

Sub Button3_Click()

' Access Active X textbox value = ActiveSheet.OLEObjects("TextBox1").Object.Value

Dim Destination_System As Integer

Dim objBAPIControl As Object 'Function Control (Collective object)

Dim sapConnection As Object 'Connection object

Set objBAPIControl = CreateObject("SAP.Functions")

Set sapConnection = objBAPIControl.Connection

Dim valu As String

sapConnection.client = "client"

sapConnection.user = "username"

sapConnection.Language = "E"

sapConnection.hostname = "ip address of sap server"

sapConnection.Password = "password"

sapConnection.SystemNumber = "instance number"

sapConnection.System = "system ID"

If sapConnection.logon(1, True) <> True Then

MsgBox "No connection to R/3!"

Exit Sub 'End program

End If

Set objUserList = objBAPIControl.Add("BAPI_SALESORDER_GETLIST")

Worksheets(2).Select

Cells.Clear

Range("A1").Font.Italic = True

Range("A2:E2").Font.Bold = True

ActiveSheet.Cells(2, 1) = "SO Number"

ActiveSheet.Cells(2, 2) = "Item No"

ActiveSheet.Cells(2, 3) = "Material No"

ActiveSheet.Cells(2, 4) = "Text"

ActiveSheet.Cells(2, 5) = "Req Qty"

Worksheets(1).Select

valu = ActiveSheet.Cells(1, 2)

Worksheets(2).Select

valu = "0000" & valu

objUserList.exports("CUSTOMER_NUMBER") = valu

returnFunc = objUserList.Call

If returnFunc = True Then

Dim objTable As Object

Set objTable = objUserList.Tables("SALES_ORDERS")

For i = 1 To objTable.RowCount

ActiveSheet.Cells(2 + i, 1) = objTable.Cell(i, 1)

ActiveSheet.Cells(2 + i, 2) = objTable.Cell(i, 2)

ActiveSheet.Cells(2 + i, 3) = objTable.Cell(i, 3)

ActiveSheet.Cells(2 + i, 4) = objTable.Cell(i, 4)

ActiveSheet.Cells(2 + i, 5) = objTable.Cell(i, 7)

Next i

End If

End Sub

if you have installed SAP gui there there would no require other files such as

OCX.SAPFunctions etc..

Excel Ref Image.

-Avirat

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question