/* RxXL_Automation_018.rex */ parse source src d_title = substr(src,src~lastpos('\')+1,src~length-src~lastpos('\')) /* In this demonstration we will read data from the Workbook created in RxXL_Automation_017 and dynamically place it in cells in our new workbook. */ slowdown = .true --Clear the screen call SysCls -- Create the Excel object if slowdown then do smsg = .infoDlg~new(d_title,'Create The Excel Object') smsg~Execute('ShowTop') end xlobj = .OleObject~New('Excel.Application') --In this demonstration I have moved all GetConstant calls to a single location /*Turn the visible attribute on so that we can see what is happening In a production application, this can be set to false */ xlobj~Visible = .true --Create a new workbook with 1 worksheet if slowdown then do smsg = .infoDlg~new(d_title,'Create a workbook with 1 worksheet') smsg~Execute('ShowTop') end xlobj~Application~SheetsInNewWorkBook = 1 xlobj~WorkBooks~Add --Add Some Headings if slowdown then do smsg = .infoDlg~new(d_title,'Add Some Headings') smsg~Execute('ShowTop') end xlobj~Cells(1,1)~Value = '01_2000' xlobj~Cells(1,2)~Value = '01_2001' xlobj~Cells(1,3)~Value = '01_2002' xlobj~Cells(1,4)~Value = '01_2003' xlobj~Cells(1,5)~Value = '01_2004' --Pull data from other workbook - note that never opened it if slowdown then do smsg = .infoDlg~new(d_title,'Pull data from other workbook - note that we never opened it') smsg~Execute('ShowTop') end xlobj~Cells(2,1)~Value = '=[RxXL_Automation_017.xls]Sales_Data!R3C2' xlobj~Cells(2,2)~Value = '=[RxXL_Automation_017.xls]Sales_Data!R4C2' xlobj~Cells(2,3)~Value = '=[RxXL_Automation_017.xls]Sales_Data!R5C2' xlobj~Cells(2,4)~Value = '=[RxXL_Automation_017.xls]Sales_Data!R6C2' xlobj~Cells(2,5)~Value = '=[RxXL_Automation_017.xls]Sales_Data!R7C2' --Give the file a name outfile = '.\RxXL_Automation_018.xls' --Turn off the alerts xlobj~DisplayAlerts = .false --Save the file if slowdown then do smsg = .infoDlg~new(d_title,'Save the workbook') smsg~Execute('ShowTop') end xlobj~ActiveSheet~SaveAs(outfile) --Close the Workbook if slowdown then do smsg = .infoDlg~new(d_title,'Close the workbook') smsg~Execute('ShowTop') end xlobj~WorkBooks(1)~Close(SaveAll) --Quit Excel if slowdown then do smsg = .infoDlg~new(d_title,'Quit Excel') smsg~Execute('ShowTop') end xlobj~Quit say 'Now re-run RxXL_Automation_017.rex to recreate the source workbook.' say 'Make a note of the values in column B' say 'Then use Excel and open RxXL_Automation_018.xls' say 'You will be prompted if want to Update the links' say 'Make a note of the current values, then Update the links' exit ::requires 'oodwin32.cls' ::class infoDlg subclass userdialog public ::method Init expose width height d_title d_text use arg d_title, d_text self~Init:super() width = 350 height = 45 rc=self~CreateCenter(width,height,d_title,,,'Arial',10) ::method DefineDialog expose width height d_title d_text forward class(super) continue self~AddButton( 1,width-60 ,height-20,50,15,'OK','Ok','DEFAULT') self~AddText(1,5,350,15,d_text) ::method Ok self~OK:super return self~finished