Guest User

Untitled

a guest
Feb 11th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. Sub SAP()
  2.  
  3. Dim sap As Object
  4. Dim conn As Object
  5.  
  6. Set sap = CreateObject("SAP.Functions")
  7. Set conn = sap.Connection
  8. conn.System = "S0P"
  9. conn.Client = ""
  10. conn.User = ""
  11. conn.Password = ""
  12. conn.Language = "PT"
  13.  
  14. If conn.logon(0, False) <> True Then
  15. MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
  16. End If
  17.  
  18.  
  19. Set SapGuiAuto = GetObject("SAPGUI") 'Utiliza o objeto da interface gráfica do SAP
  20. Set SAPApp = SapGuiAuto.GetScriptingEngine 'Conecta ao SAP que está rodando no momento
  21. Set SAPCon = SAPApp.Children(0) 'Encontra o primeiro sistema que está conectado
  22. Set session = SAPCon.Children(0) 'Encontra a primeira sessão (janela) dessa conexão
  23.  
  24. If Not IsObject(Application) Then
  25. Set SapGuiAuto = GetObject("SAPGUI")
  26. End If
  27. If Not IsObject(Connection) Then
  28. End If
  29. If Not IsObject(session) Then
  30. End If
  31. If IsObject(WScript) Then
  32. WScript.ConnectObject session, "on"
  33. WScript.ConnectObject Application, "on"
  34. End If
  35. session.findById("wnd[0]").maximize
  36.  
  37. Dim objExcel
  38. Dim objSheet, intRow, aux, Log
  39. Set objExcel = GetObject(, "Excel.Application")
  40. Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
  41.  
  42. DataInicial = Range("H2")
  43. DataFinal = Range("H3")
  44.  
  45. session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMB51"
  46.  
  47. End Sub
  48.  
  49. Set SapGuiAuto = GetObject("SAPGUI")
Add Comment
Please, Sign In to add comment