大家早上好!用VBA登錄SAP
我一直在尋找最後的日子裏的解決方案,但我真的沒有設法成功:我試圖讓一個vba代碼:1登錄到SAP,2-運行一些交易3-出口到Excel中。
但即使是「登錄SAP」部分也不行!
我試了幾個代碼,在一個下面打開SAP登錄屏幕,但在任何領域不填。我曾經CreateObject("Sapgui.ScriptingCtrl.1")
:
Sub Entrar_SAP()
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("xxxxxxx)", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "pass"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"
session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
session.findById("wnd[0]").sendVKey 0
一個又一個,與CreateObject("SAP.Functions")
,顯示: 「獲得RFC錯誤沒有對功能模塊RFC PING RFC授權。」
代碼:
'Declaration
Dim objBAPIControl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Set objBAPIControl = CreateObject("SAP.Functions")
Set sapConnection = objBAPIControl.Connection
sapConnection.Client = "xxxxx"
sapConnection.User = "xxxxxx"
sapConnection.Language = "PT"
sapConnection.hostname = "xxxxx"
sapConnection.Password = "xxxxxxxx" 'Fake password
sapConnection.SystemNumber = "4"
sapConnection.System = "xxxxxx)"
sapConnection.Logon
If sapConnection.Logon(1, True) <> True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
End If
能
人請幫幫我?謝謝!!
請編輯您的問題,以便代碼可讀。在代碼前留下一個空行,並將每行縮進4個空格,如果要顯示縮進的代碼塊,則更多。 – ChipsLetten
謝謝,我剛剛編輯! –