Jump to content

getting existing excel and getting error


Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...