Skip to Content
0

Not able to automate List->Export->Spreadsheet option using vbs for SAP GUI Automation

May 22, 2017 at 12:56 PM

44

avatar image
Former Member

Hi,

I have recently started SAP Automation and I have stuck in my very first task. The problem is in the code where I click on the List option on the top menu bar and then go to Export and then choose Spreadsheet option. There is not shortcut key for that option also. But after recording the task this part does not works and I get the error control id not found.

PFB the code I am using:

Dim d1
dim m1
dim y1
dim d2
dim m2
dim y3
dim today
dim lastday
dim todate
dim fromdate
today=CDate(DateAdd("d",-1,date))
d1=Day(today)
m1=Month(today)
y1=Year(today)
todate=y1 & "/" & m1 & "/" & d1
lastday=CDate(DateAdd("d",-7,date))
d2=Day(lastday)
m2=Month(lastday)
y2=Year(lastday)
fromdate=y2 & "/" & m2 & "/" & d2
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]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "sa38"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxt").text = "ZVRR0013"
session.findById("wnd[0]/usr/ctxt").caretPosition = 8
session.findById("wnd[0]/tbar[1]/btn[18]").press
session.findById("wnd[1]/usr/ctxt").text = "ABCD"
session.findById("wnd[1]/usr/ctxt").caretPosition = 12
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxt[2]").text = fromdate
session.findById("wnd[0]/usr/ctxt[3]").text = todate
session.findById("wnd[0]/usr/ctxt[3]").setFocus
session.findById("wnd[0]/usr/ctxt[3]").caretPosition = 9
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").setCurrentCell -1,"MESSAGE"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "MESSAGE"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&COL0"
session.findById("wnd[1]/usr/tabsG_TS_ALV/tabpALV_M_R1/ssub/1/3/cntlCONTAINER2_LAYO/shellcont/shell").currentCellRow = 22
session.findById("wnd[1]/usr/tabsG_TS_ALV/tabpALV_M_R1/ssub/1/3/cntlCONTAINER2_LAYO/shellcont/shell").firstVisibleRow = 15
session.findById("wnd[1]/usr/tabsG_TS_ALV/tabpALV_M_R1/ssub/1/3/cntlCONTAINER2_LAYO/shellcont/shell").selectedRows = "1,22,23"
session.findById("wnd[1]/usr/tabsG_TS_ALV/tabpALV_M_R1/ssub/1/3/cntlCONTAINER2_LAYO/shellcont/shell").pressToolbarButton "DTC_UPPOS1"
session.findById("wnd[1]/usr/tabsG_TS_ALV/tabpALV_M_R1/ssub/1/3/cntlCONTAINER2_LAYO/shellcont/shell").pressToolbarButton "DTC_DOWN"
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]").maximize
session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[1]").select
session.findById("wnd[1]/usr/ctxt[0]").setFocus
session.findById("wnd[1]/usr/ctxt[0]").caretPosition = 0
session.findById("wnd[1]").sendVKey 4
session.findById("wnd[2]/tbar[0]/btn[11]").press
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers