Hi Abjac,
I just wanted to make sure...
Requirements:
1. The table to be imported is located in the first mode on the screen.
2. The pathc:\ tmpexists.
3. Excelis installed.
Now you cantry the following:
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
'The following command should only guarantee that the table is at the top. Ifit does not work, you need to recordherethe commanditself.
'Perhaps similar as : session.findById("wnd[1]/usr/btnPB_FIRST_PAGE").press
session.findById("wnd[1]").sendVKey 80
Set xclApp = CreateObject("Excel.Application")
xclApp.workbooks.add
xclApp.Visible = True
xclapp.DisplayAlerts = false
myFile = "c:\tmp\test.xlsx"
k = 1
do
set myTable = session.findById("wnd[1]/usr/tbl/HOAG/AK_POSTPROCESSINGTC_BSID_MODAL")
if k = 1 then
'rows = myTable.RowCount
cols = myTable.Columns.Count
vRows = myTable.VisibleRowCount
for j = 0 to cols - 1
xclApp.ActiveWorkbook.sheets(1).Cells(k,j + 1).Value = myTable.columns.elementAt(j).title
next
k = k + 1
end if
for i = 0 to vRows - 1
l = 1
for j = 0 to Cols - 1
on error resume next
myVariable = trim(myTable.GetCell(i,j).Text)
if err.number <> 0 then exit for
on error goto 0
if left(right(myVariable,3),1) = "," then
myVariable = replace(myVariable, "." , "")
myVariable = replace(myVariable, "," , "")
xclApp.ActiveWorkbook.sheets(1).Cells(k,l).Value = myVariable/100
else
xclApp.ActiveWorkbook.sheets(1).Cells(k,l).Value = myVariable
end if
l = l + 1
next
if err.number <> 0 then exit for
k = k + 1
next
if err.number <> 0 then exit do
myTable.VerticalScrollbar.Position = myTable.VerticalScrollbar.Position + vRows
Loop
xclapp.ActiveWorkbook.SaveAs myFile
'xclapp.ActiveWorkbook.Close
Set xclwbk = Nothing
Set xclsheet = Nothing
'xclapp.Quit
set xclapp = Nothing
Regards,
ScriptMan