cancel
Showing results for 
Search instead for 
Did you mean: 

How to scroll down while runing a macro to update data on SAP

DMUIDGUEL
Newcomer
0 Kudos

Hello everyone! So I have done a macro (Excel) to help me update some information on Sap, the script works perfectly but I'm having some trouble to add all de information I need because the table doesn't scroll down. How can I solve this problem?


Dim SapGui
Dim Application
Dim connection
Dim session
Dim WSHShell
Dim SapGuiAuto
Dim WScript
Dim ultimaCelula As Integer
Dim i As Integer
Dim x As Integer

 

   
If Not IsObject(Application) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = Application.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 Application, "on"
End If

 

session.findById("wnd[0]/tbar[0]/okcd").Text = "******************"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtSO_EQUNR-LOW").Text = "************" 'NUMERO EQUIPAMENTO
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/shellcont/shell").selectItem "Z001", "Column01" 'VERIFICAR ANTES A SEGUIR
session.findById("wnd[0]/shellcont/shell").ensureVisibleHorizontalItem "Z001", "Column01"
session.findById("wnd[0]/shellcont/shell").clickLink "Z001", "Column01"

 

x = 0
Do
   ultimaCelula = Cells(ActiveSheet.UsedRange.Rows.Count, 1).Row
   For i = 2 To ultimaCelula

 

session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-LOCALISATION[0," & x & "]").Text = Cells(i, "A").Value 'RFS
session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-COTE[2," & x & "]").Text = Cells(i, "B").Value         'COTAÇÃO
session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-NATURE[3," & x & "]").Text = Cells(i, "C").Value       'NATUREZA
session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-GRAVITE[6," & x & "]").Text = Cells(i, "D").Value      'GRAVIDADE
session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/txtZSPA_ST_DEFAUT_DQ-COMMENTAIRES[7," & x & "]").Text = Cells(i, "E").Value   'COMENTARIO
session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-PARTICULARITE[11," & x & "]").Text = Cells(i, "F").Value  'ADICIONAL
'session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-PARTICULARITE[11," & x & "]").SetFocus
'session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/tblSAPMZSPA_DQTC_DEFECTS/ctxtZSPA_ST_DEFAUT_DQ-PARTICULARITE[11," & x & "]").caretPosition = 2
'session.findById("wnd[0]").sendVKey 0
'session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/btnV_NEXT_PAGE").press
'session.findById("wnd[0]/usr/tabsTS_TABS/tabpTS_TABS_FC2/ssubTS_TABS_SCA:SAPMZSPA_DQ:9102/btnV_NEXT_PAGE").press

 

x = x + 1

 

Next i

 

Loop Until Cells(i, "A").Value = ""

 

End Sub

This is the code I'm already using.

07678f90-62c9-4265-9998-c956e4842084.jpg

BiserSimeonov
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello DMUIDGUEL ,
BiserSimeonov
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello DMUIDGUEL , I am not sure if this question should be related to SAP Automation Pilot. Can you please let us know which exact product you have used for the DB table you had referred to?

Accepted Solutions (0)

Answers (0)