'
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus
'Appl.Wait Now + TimeValue("0:00:15")
Set WSHShell = CreateObject("WScript.Shell")
'Appl.Wait Now + TimeValue("0:00:15")
Do Until WSHShell.AppActivate("SAP Logon ")
'Appl.Wait Now + TimeValue("0:00:15")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set Connection = Applic.OpenConnection("ERP - ECC Produção", True)
Set session = Connection.Children(0)
'Appl.Wait Now + TimeValue("0:00:15")
On Error Resume Next
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "500"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "LOGUIN"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "SENHA"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"
session.findById("wnd[0]").sendVKey 0
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Appl = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Appl.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject session, "on"
wscript.ConnectObject Appl, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ztmm002"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radRB_R").Select
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").setCurrentCell 1, "TEXT"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/tbar[0]/btn[2]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/cntlCC9200/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlCC9200/shellcont/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "\\fsextrema02\ProgramacaoControleE-commerce\Inteligência de Estoque\Relatório Fluxo de Processo 7017-7006\7017\Relatorio V2\Sap Extrações"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "RS7017.XLSX"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
session.findById("wnd[1]/tbar[0]/btn[11]").press
Pergunta
Ramiro Isídio
Bom dia pessoal!
Criei um código em VBA junto ao SAP, para entrar em uma transaçao e realizar a extração do relatorio substituindo em um determinado diretorio.
Porém, nessas extrações, o SAP abre o arquivo, e não estou conseguindo fechar ele, alguém poderia auxiliar? Segue código abaixo:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub RelatorioEmb()
'
' RelatorioEmb Macro
'
'
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus
'Appl.Wait Now + TimeValue("0:00:15")
Set WSHShell = CreateObject("WScript.Shell")
'Appl.Wait Now + TimeValue("0:00:15")
Do Until WSHShell.AppActivate("SAP Logon ")
'Appl.Wait Now + TimeValue("0:00:15")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set Connection = Applic.OpenConnection("ERP - ECC Produção", True)
Set session = Connection.Children(0)
'Appl.Wait Now + TimeValue("0:00:15")
On Error Resume Next
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "500"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "LOGUIN"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "SENHA"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"
session.findById("wnd[0]").sendVKey 0
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Appl = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Appl.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject session, "on"
wscript.ConnectObject Appl, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ztmm002"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radRB_R").Select
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").setCurrentCell 1, "TEXT"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/tbar[0]/btn[2]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/cntlCC9200/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlCC9200/shellcont/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "\\fsextrema02\ProgramacaoControleE-commerce\Inteligência de Estoque\Relatório Fluxo de Processo 7017-7006\7017\Relatorio V2\Sap Extrações"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "RS7017.XLSX"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
session.findById("wnd[1]/tbar[0]/btn[11]").press
Workbooks("RS7017.XLSX").Close
Set session = Nothing
Connection.CloseSession ("ses[0]")
Set Connection = Nothing
Set sap = Nothing
End Sub
Link para o comentário
Compartilhar em outros sites
3 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.