Open a specific Excel-file?

Hi,

 

with the include-file "ole.inc" I can open up a new empty excel-instance. This code line is: objExcel = oleCreateAutoObject("Excel.Application"). But now, I will do this: Create a new instance and load a specific .xlsm file in this new empty Excel instance. How can I do this?

 

Also I have this code:

 

//Open an existing document
        oleGet(objExcel, "Workbooks", objWorkbooks)
        clear args
        put(args, "C:\\Users\\amehto4\\Desktop\\ReqExportTemplate.xlsm")
        oleMethod(objWorkbooks, "Open", args, objWorkbook)

 

But this give a problem in line oleMethod(objWorkbooks, "Open", args, objWorkbook). The failure is:

-> Parameter mit dem Wert null OleAutoObj wurde der Argumentposition 1 übergeben.

I don't know which parameter Doors with this line mean... Will "Argumentposition 1" mean, that "objWorkbook" is null? What expects Doors at this parameter field?

 

Can anybody help me?


tobi_mehrl - Tue Oct 27 08:34:55 EDT 2015

Re: Open a specific Excel-file?
DOORSHAM - Wed Oct 28 13:12:43 EDT 2015

Following should work if excel file exists.

 

 

//OpenWorkbook.dxl
/*
Opens a workbook
*/
string SetExcelCell(OleAutoObj objSheet, int xCellLoc, int yCellLoc, string property, string value)
{ OleAutoObj objCell = null
  OleAutoArgs autoArgs = create
  string result = null
  put(autoArgs, yCellLoc)
  put(autoArgs, xCellLoc)
  result = oleMethod(objSheet,"Cells",autoArgs, objCell)
  if (result == null)
  {  OleAutoObj objInterior = null
     result = olePut(objCell, property, value)
  }
  return result
}
OleAutoObj objExcel =oleCreateAutoObject("Excel.Application")
OleAutoArgs args = create
OleAutoArgs autoArgs = create
OleAutoObj objSpreadSheet
OleAutoObj objWorkbooks
bool excelVisible

//Make Excel visible to the user
oleGet(objExcel, "visible", excelVisible)
if (excelVisible == false) olePut(objExcel,"visible",true)

//Add new workbook
oleGet(objExcel,"Workbooks", objWorkbooks)
oleMethod(objWorkbooks,"Add")
clear(autoArgs)


oleGet(objExcel, "Workbooks", objWorkbooks)
clear args
string sFILE= "H:\\book2.xlsx"
sFILE = "C:\\Users\\amehto4\\Desktop\\ReqExportTemplate.xlsm"
put(args, sFILE )
string s = oleMethod(objWorkbooks, "Open", args, objWorkbook)
print s