VBA读SAP系统table里面的数据,如何才能得到table ID?
我用VBA操作并读SAP的数据,当打开SAP一个页面,页面上显示table, table里面有我需要读的数据,但是没法看出table ID。
****************************************************************
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/okcd").Text = "SE23"
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-MATNR").Text = "45243"
Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-BERID").Text = "4332"
Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-BERID").SetFocus
Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-BERID").caretPosition = 4
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/usr/btnBUTTON_EZ_PS").press
Session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W").Select ‘到这一步都运行很好 ,目标页面已打开。
Set Table = Session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760") '这里table id即路径是错误的,从而买法读到数据
Rows = Table.RowCount() - 1
For k = 0 To Rows
xlSheetreport.Cells(i, k + 3) = Table.GetCellValue(k, 2)
Next k
****************************************************************
这个 table id不对, wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760
在SAP,能够查到的信息Program name: SAPMM61R和Table name: MDSU
如果用SAP的录脚本的功能,在这个table(grid)里面鼠标随便点点,录下来的信息如下。
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,4]").setFocus
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,4]").caretPosition = 11
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,6]").setFocus
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,6]").caretPosition = 12
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,7]").setFocus
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,7]").caretPosition = 12
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS").columns.elementAt(2).width = 12
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS").columns.elementAt(3).width = 12
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0770/tabsPS_TAB/tabpPS_W/ssubPS_SUBSCR:SAPMM61R:0760/tblSAPMM61RTC_PS/txtMDSU-MNG02[2,7]").caretPosition = 14
session.findById("wnd[0]").sendVKey 2
从以上信息,能分析得出table的ID吗?
Session.findById("?")
非常感谢!