WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Accessing an Existing Copy of Excel

 Keywords:  Accessing Existing Copy Excel

Question:

I have done a search and found info on how to read an excel spreadsheet by opening it using ObjectOpen, however, I cannot seem to find an example of how to read a worksheet that is already open in excel, without opening another instance. Is this possible with Winbatch?

The reason I am asking is that an application I use generates a temporary excel spreadsheet, opens it and presents it to the User. I would like to put up a button that calls a Winbatch script to do further processing.

My problem is I cannot seem to get to the data using OLE unless I do an ObjectOpen, which creates a new instance; it does not use the existing spreadsheet currently open in excel.

Any advice would be appreciated.

Answer:

Here is some code to help get you started:
objXL = ObjectAccess("Excel.Application",@true)
objXL.Visible = @TRUE
objActiveWorkbook = objXL.ActiveWorkbook
if objActiveWorkbook == 0
	Message("","No active workbook")
	ObjectClose(objXL)
	exit
endif
wrkbkname = objActiveWorkbook.Name
Message("Active WorkBook Name",wrkbkname)

objActiveSheet = objXL.ActiveSheet
if objActiveSheet == 0
	Message("","No active workSheet")
	ObjectClose(objActiveWorkbook)
	ObjectClose(objXL)
	exit
endif

wrkshtname = objActiveSheet.Name
Message("Active WorkSheet Name",wrkshtname)

ObjectClose(objActiveSheet)
ObjectClose(objActiveWorkbook)
ObjectClose(objXL)

Article ID:   W15623
File Created: 2003:05:13:11:29:18
Last Updated: 2003:05:13:11:29:18