Option Explicit
Dim Appl, SapGuiAuto, Connection, Session, WScript, wshShell, proc, ApplSAP, Creator 'Application,SapGuiAuto, Connection, session, WScript'
Sub Automatizacao_SAP()
'Inicia o aplicativo SAP se não estiver aberto'
Set wshShell = CreateObject("WScript.Shell")
Set proc = wshShell.Exec("C:\Program Files\SAP\NWBC800\NWBC.exe")
'Aguarda o aplicativo SAP abrir completamente'
Application.Wait Now + TimeValue("0:00:5")
'Conexao com o SAP'
If Not IsObject(Appl) Then
Set SapGuiAuto = GetObject("SAPGUISERVER")
Set Appl = SapGuiAuto.GetScriptingEngine
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject Application, "on"
End If
'Rotina'
Session.findById("wnd[0]").resizeWorkingPane 217, 18, False
Session.findById("wnd[0]/tbar[0]/okcd").Text = "ME23N" 'Insere a transacao'
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/tbar[1]/btn[17]").press
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/radMEPO_SELECT-BSTYP_B").SetFocus
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/radMEPO_SELECT-BSTYP_B").Select
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").Text = "4101212624"
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").SetFocus
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").caretPosition = 10
Session.findById("wnd[1]/tbar[0]/btn[0]").press
End Sub