>>>I am wondering if there is a way to have a VFP application through COM open an excel sheet and quickly identify certain cells. I don't want to go through the entire sheet cell by cell looking for what I need. I could try to do a find, but I wonder if there is a better way. In word I could create bookmarks, but I don't see that in excel.
>>>
>>>Cesar
>>
>>In Excel you can apply a "name" to one, or a range of, cells. Will this give you what you need?
>
>Yes, it might, can you then search for that name and it will give you the cell location?
Hi Cesar,
Name is like bookmarks in word in a way. First of all keep in mind that a name 'RefersTo' a range not to only a cell (might be). A range might be a cell, a group of cells or even union of different group of cells. 'Name' refersto all that range and could directly be used in formulas (ie: =sum(myName)).
To test the code create a test workbook with different name definitions (visible = .t. at first line slows down but I wanted to show what's going on):
lparameters tcXlsFullPath
oExcel = createobject('Excel.Application')
WITH oExcel
.visible = .t.
.Workbooks.Open(tcXlsFullPath)
WITH .Activeworkbook
.WorkSheets.Add
WITH .ActiveSheet
.Name = 'Bookmarks'
FOR ix=1 to oExcel.Activeworkbook.Names.Count
.Cells(ix, 1).Value = oExcel.Activeworkbook.Names(ix).Name
.Cells(ix, 2).Value = "'" + oExcel.Activeworkbook.Names(ix).RefersTo
ENDFOR
.Columns("A:B").AutoFit
WAIT timeout 3
FOR ix=1 to oExcel.Activeworkbook.Names.Count
lcRefers = oExcel.Activeworkbook.Names(ix).RefersTo
lcSheet = substr(lcRefers,2,at('!',lcRefers)-2)
lcAddress = chrtran(substr(lcRefers,at('!',lcRefers)+1),'$','')
oExcel.Activeworkbook.Sheets(lcSheet).Activate
oExcel.Activeworkbook.ActiveSheet.Range(lcAddress).Select
WAIT timeout 2
ENDFOR
ENDWITH
ENDWITH
ENDWITH
Cetin