Hi,
no need to be frustrated any more ( well, I hope ), here is my minimal example to open file in Excel.
The trick is to separate Method name, and its parameters, which should be passed as array of variants.
Tested with MS Office 2007, elemental student version.
See here:
uses "COM"
%Max_Param = 1
dim pXlApp as dword
dim pXlBooks as dword
dim vParam(%Max_Param) as variant
dim vRetVal as variant
dim RetVal as long
'---Try to create an Excel application reference
pXlApp = COM_CreateObject("Excel.Application", RetVal)
'---If OK we will procede
IF COM_Succeeded(RetVal) THEN
'---Try to set excel visible
vParam(1) = 1
if COM_Succeeded(COM_SetProperty(pXlApp, "Visible", 1, vParam)) then
'---OK, we got it
msgbox 0, "Now Excel should be visible!"
'---Now add a new workbook ...
if COM_Succeeded(COM_GetProperty(pXlApp, "Workbooks", vRetVal)) then
pXlBooks = vRetVal
' -- Com call method takes parameters from VARIANT array!
vParam(1) = "D:\thinBasic\Projekte\GraphWizard\GraphWiz_Output_v1.xls"
if COM_Succeeded(COM_CallMethod(pXlBooks, "Open", 1, vParam(1), vRetVal)) then
msgbox 0, "File opened!"
else
msgbox 0, "File open failed, why ... why ... why"
end if
end if
else
msgbox 0, "Visible fails"
end if
END IF
'--- Time to release the allocated interface objects
if isfalse(COM_Succeeded(COM_Release(pXlBooks))) then
msgbox 0, "Workbooks release fails"
end if
if isfalse(COM_Succeeded(COM_Release(pXlApp))) then
msgbox 0, "Excel application release fails"
end if
Have a nice day,
Petr
Bookmarks