joeloyzaga Posted March 20, 2009 Share Posted March 20, 2009 image attached ; Example getting an Object using it's class name ; ; Excel must be activated for this example to be successfull ;$oExcel = ObjGet("","Excel.Application"); Get an existing Excel Object ;if @error then ;Msgbox (0,"ExcelTest","Error Getting an active Excel Object. Error code: " & hex(@error,8)) ;exit ;endif ;$oExcel.Visible = 1 ; Let the guy show himself ;$oExcel.workbooks.add ; Add a new workbook ;exit ; Example getting an Object using a file name ; ; An Excel file with filename Worksheet.xls must be created in the root directory ; of the C:\ drive in order for this example to work. $FileName="C:\Data\MEVI\Resources\MEVI.xls" if not FileExists($FileName) then Msgbox (0,"Excel File Test","Can't run this test, because you didn't create the Excel file "& $FileName) Exit endif $oExcelDoc = ObjGet($FileName); Get an Excel Object from an existing filename $oExcel.Visible = 1 ; Let the guy show himself $oExcel.workbooks.add ; Add a new workbook Link to comment Share on other sites More sharing options...
foster74 Posted March 20, 2009 Share Posted March 20, 2009 This may be a silly question but do you have Excel running when you start this script? Link to comment Share on other sites More sharing options...
Spiff59 Posted March 20, 2009 Share Posted March 20, 2009 I don't know the correct terminology to describe this, but the object returned from an ObjGet with the filename parameter appears to be more-generic, less-qualified, at a higher-level, than that returned by a classname call. Inserting this line after the ObjGet generates a second object (oExcel), based upon the first (OExcelDoc), which then functions correctly: $oExcelDoc = ObjGet($FileName); Get an Excel Object from an existing filename $oExcel = $oExcelDoc.Application $oExcel.Visible = 1 ; Let the guy show himself Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now