excel 如何解决编译错误:VBA子程序语法错误?

ttcibm8c  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(163)

我有这个子调用执行其他两个子在程序中,但当我试图执行它弹出编译错误:语法错误就在子的第一行。

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)\SAP\FrontEnd\SAPgui\saplogon.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

我被这个错误卡住了:
一个三个三个一个
我希望能够执行这个宏

juud5qan

juud5qan1#

你的代码没有给我一个编译错误。
这是我用来与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)\SAP\FrontEnd\SAPgui\saplogon.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

相关问题