Code: Alles auswählen.
Sub ReadTable()
Dim FUBAU_rfc_read_table As Object
Dim functionCtrl As Object
Dim T_I_Options As Object
Dim T_I_Fields As Object
Dim T_E_Data As Object
Dim i, x As Integer
Dim strDataRow As String
Dim DataRow As Variant
Dim Col As Boolean
Col = False
Set functionCtrl = CreateObject("SAP.Functions")
Set SapConnection = functionCtrl.Connection
SapConnection.ApplicationServer = ""
SapConnection.Client = ""
SapConnection.User = ""
SapConnection.Password = ""
SapConnection.System = ""
SapConnection.Language = ""
If SapConnection.Logon(0, True) <> True Then
MsgBox "keine Verbindung zu SAP mögl."
Exit Sub
Else
MsgBox "Verbindung zu SAP hergestellt." + Chr(13) + "Folgende Systemdaten wurden übermittelt:" + Chr(13) + Chr(13) + SapConnection.User
End If
Set FUBAU_rfc_read_table = functionCtrl.Add("RFC_READ_TABLE")
With FUBAU_rfc_read_table
.exports("QUERY_TABLE") = InputBox("Bitte Tabellenname eingeben")
.exports("DELIMITER") = "|" 'Delimiter
End With
Set T_I_Options = FUBAU_rfc_read_table.tables("OPTIONS")
Set T_I_Fields = FUBAU_rfc_read_table.tables("FIELDS")
Set T_E_Data = FUBAU_rfc_read_table.tables("DATA")
'Aufruf des FUBAs
ret = FUBAU_rfc_read_table.call
'Übetragen der Daten in Excel-Tabelle (z.B. immer in Tabelle1)
If T_E_Data.RowCount > 0 And ret = True Then
For i = 1 To T_E_Data.RowCount
strDataRow = T_E_Data(i, 1)
DataRow = Split(strDataRow, "|")
'Spaltenüberschriften an Excel übergeben
If Col = False Then
For x = 0 To UBound(DataRow)
Tabelle1.Cells(1, x + 1).Value = T_I_Fields(x + 1, 1)
Next x
Col = True
End If
For x = 0 To UBound(DataRow)
Tabelle1.Cells(i + 1, x + 1).Value = DataRow(x)
Next x
Next i
End If
End Sub