我有这个子程序正在调用执行程序中的其他两个子程序,但是当我试图执行它时,它弹出了编译错误:语法错误,就在子程序的第一行。
Sub MacroPrimaria()
Call SAPOpenSessionFromLogon
Application.Wait Now + TimeValue("00:00:05")
Call executarsap
MsgBox ("PROCESSAMENTO FINALIZADO")
End Sub
Sub SAPOpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Dim WSHShell
Shell "C:Program Files (x86)SAPFrontEndSAPguisaplogon.exe", vbNormalFocus
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set connection = Applic.OpenConnection("S/4 HANA - PRODUÇÃO", True)
Set session = connection.Children(0)
session.findById("wnd[0]").maximize
End Sub
Sub executarsap()
Dim Application, SapGuiAuto, connection, session, WScrip
'**IMPORTANTE**: Abaixo daqui, basta colar o scrip gerado pela gravação do SAP, sem retirar nada:
'This sub it's okay and has confidential stuff so its just to know.
End Sub
我被困在这个错误的行:
"Sub MacroPrimaria()"
"Sub SAPOpenSessionFromLogon()"
我希望能够执行宏
你的代码没有给我一个编译错误。
这是我用来与SAP交互的代码,到目前为止它还没有给我任何问题(我不记得我在互联网上找到它了)。
也许有帮助。
Public Sub Execute_SAP()
'Login details here.
Dim LogInDetail As Variant
LogInDetail = Array("***YOUR USER NAME***", "***YOUR PASSWORD***")
'Open the SAP Log-In screen and wait for it to load.
Shell "C:Program Files (x86)SAPFrontEndSAPguisaplogon.exe", 4
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
Do Until WshShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WshShell = Nothing
Dim SAPGui As Object
Set SAPGui = GetObject("SAPGUI")
Dim Appl As Object
Set Appl = SAPGui.GetScriptingEngine
Dim Connection As Object
Set Connection = Appl.OpenConnection("S/4 HANA - PRODUÇÃO", True)
Dim Session As Object
Set Session = Connection.Children(0)
With Session
'Log-in to the session.
.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "300"
'The next two lines accept the username and password - LogInDetail variant holds those two values.
.findById("wnd[0]/usr/txtRSYST-BNAME").Text = LogInDetail(0)
.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = LogInDetail(1)
.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
.findById("wnd[0]").maximize
.findById("wnd[0]").SendVKey 0 'ENTER
'Rest of SAP code - each line starts with
' .findById("wnd[0]
'Use SAPs macro recorder to get the detail... is probably what you've got in executearsap()
End With
End Sub
感谢您的帮助!
显然,我创建脚本的文件被损坏了,当我创建一个新文件时,代码可以正常运行。