Jump to content
Fórum Script Brasil
  • 0

Script SAP VBA


Adriano321souza

Question

Bom dia, estou tentando editar um script VBA SAP para automatizar uma rotina, mas não estou conseguindo. Podem me ajudar. Preciso lançar o dado no ítem Equip. Superior e o código foi feito para lançar no ítem Loc. Instalação e não tenho acesso para gravar macro no SAP.

 

Segue o código original

Option Explicit

 

Sub macro_cadastro()

 

Dim Appl, SapGuiAuto, Connection, session, WScript

Dim ultimacelula As Integer

Dim i As Integer

 

   If Not IsObject(Appl) 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

 

ultimacelula = Cells(ActiveSheet.UsedRange.Rows.Count, 1).Row

 

For i = 2 To ultimacelula

    session.findById("wnd[0]/tbar[0]/okcd").Text = "IE01"

    session.findById("wnd[0]").sendVKey 0

    session.findById("wnd[0]/usr/ctxtRM63E-EQTYP").Text = "R"

    session.findById("wnd[0]/usr/ctxtRM63E-EQTYP").SetFocus

    session.findById("wnd[0]/usr/ctxtRM63E-EQTYP").caretPosition = 1

    session.findById("wnd[0]").sendVKey 0

    session.findById("wnd[0]/usr/subSUB_EQKO:SAPLITO0:0152/subSUB_0152B:SAPLITO0:1525/txtITOB-SHTXT").Text = Cells(i, "c")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\01/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1020/ctxtITOB-BEGRU").Text = Cells(i, "e")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\01/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1020/subSUB_1020A:SAPLITO0:1025/ctxtITOB-EQART").Text = Cells(i, "d")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\01/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1020/ctxtITOB-BEGRU").SetFocus

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\01/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1020/ctxtITOB-BEGRU").caretPosition = 3

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02").Select

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/ctxtITOB-SWERK").Text = Cells(i, "f")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/ctxtITOB-BEBER").Text = Cells(i, "g")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/ctxtITOB-ABCKZ").Text = Cells(i, "h")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/txtITOB-EQFNR").Text = Cells(i, "i")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/txtITOB-EQFNR").SetFocus

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\02/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1050/txtITOB-EQFNR").caretPosition = 23

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\03").Select

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\03/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1052/ctxtITOB-GSBER").Text = Cells(i, "j")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\03/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1052/ctxtITOB-KOSTL").Text = Cells(i, "k")

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\03/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1052/ctxtITOB-KOSTL").SetFocus

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\03/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1052/ctxtITOB-KOSTL").caretPosition = 10

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\04").Select

    session.findById("wnd[0]/usr/tabsTABSTRIP/tabpT\04/ssubSUB_DATA:SAPLITO0:0102/subSUB_0102A:SAPLITO0:1060/subSUB_1060A:SAPLITO0:1065/btnFCODE_CIPL").press

    session.findById("wnd[1]/usr/ctxtIEQINSTALL-TPLNR").Text = Cells(i, "l")

    session.findById("wnd[1]/usr/ctxtIEQINSTALL-TPLNR").caretPosition = 25

    session.findById("wnd[1]/tbar[0]/btn[16]").press

    session.findById("wnd[2]/tbar[0]/btn[0]").press

    session.findById("wnd[0]/tbar[0]/btn[11]").press

Next i

 

End Sub

 

17049800808182915972795658374260.jpg

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.8k
×
×
  • Create New...