cancel
Showing results for 
Search instead for 
Did you mean: 

Connection with Excel

Former Member
0 Kudos

Hello,

I have a excel sheet that have 3 buttons one to connect to a sap system, one to connect with a function in a sap system and download a table from there and show in the excel sheet, and one that i want to connect to another function and upload the data in the sheet and send it to the function. The download is working well but the upload don't work. here is the code.

' Declaration for the necessary objects

Dim objBAPIControl, objConnection As Object

Dim objTeste As SAPFunctionsOCX.Function

Dim objTable As SAPTableFactoryCtrl.Table

Dim login As Boolean

Private Sub DOWNLOAD_Click()

On Error Resume Next

' The required BAPI

Set objTable = Nothing

Set objTeste = objBAPIControl.Add("ZPD_TESTE_EXCEL")

If objTeste.Call Then

Set objTable = objTeste.Tables("T_INTER")

For i = 1 To objTable.RowCount

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

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

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

Next i

Else

MsgBox "Erro a chamar a função."

End If

' objTable.AppendGridData

End Sub

Private Sub LOGON_Click()

If login = False Then

' Setting the necessary variables for R/3 connection

Set objBAPIControl = CreateObject("SAP.Functions")

Set objConnection = objBAPIControl.Connection

LOGON.Caption = "LOGON"

objConnection.Client = "800"

objConnection.User = "ACCJOSE"

objConnection.Language = "PT"

' Establish a connection

If objConnection.LOGON(0, False) Then

login = True

MsgBox "Ligação estabelecida."

LOGON.Caption = "LOGOFF"

End If

Else

login = False

objConnection.LOGOFF

Set objConnection = Nothing

Set objBAPIControl = Nothing

Set objTeste = Nothing

Set objTable = Nothing

LOGON.Caption = "LOGON"

End If

End Sub

Private Sub UPLOAD_Click()

On Error Resume Next

' The required BAPI

Set objTable2 = Nothing

Set objTeste2 = objBAPIControl2.Add("ZPD_TESTE_UP")

If objTeste2.Call Then

Set objTable2 = objTeste2.Tables("T_UP")

For i = 1 To ActiveSheet.RowCount

objTable2.Cell(i, 1) = ActiveSheet.Cells(8 + i, 1)

objTable2.Cell(i, 2) = ActiveSheet.Cells(8 + i, 2)

objTable2.Cell(i, 3) = ActiveSheet.Cells(8 + i, 3)

Next i

Else

MsgBox "Erro a chamar a função."

End If

objTable.AppendGridData

End Sub

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ricardo - I am getting "User defined Type not defined" error on "SAPTableFactoryCtrl.Table"

can you tell me which REFERENCE do I need to select in EXCEL.

Thansk!