Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to cycle through sheets of excel workbook.

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi.
I got an excel workbook with about 60 sheets.
On every sheet there is same kind of data at same cells per sheet.
I like to retrieve that data and put it in a vfp-table.

I know how to create an excel object. But don't know the syntax for cycling through the (I call it) sheets-collection to retrieve e.g. the value of cell A12.

Any suggestion?

-Bart
 
Something long the lines of:

FOR EACH oSheet in oXL.ActiveWorkbook
uValue = oSheet.Cells("A12").Value
* do something with it
ENDFOR

Tamar
 
Here are some code snippets that I am using for a client to look at the name of each individual worksheet and then look on that chosen worksheet for a specific cell value.

Code:
tmpsheet = CREATEOBJECT('excel.Application')
oExcel = tmpsheet.APPLICATION

mlMonthSheet = .F.
mnMaxWeek = 0
mnMaxSheet = oExcel.ActiveWorkbook.Sheets.COUNT
FOR SheetCntr = 1 TO mnMaxSheet
   mcSheetName = oExcel.ActiveWorkbook.Sheets(SheetCntr).NAME

   IF mcSheetName = mcThisMonthSheet
      mlMonthSheet = .T.
      EXIT
   ENDIF
ENDFOR

* --- Select Desired Worksheet ---
oExcel.Sheets(mcThisMonthSheet).SELECT
xlSheet = oExcel.activesheet

* --- Find Value of 'NAME' Cell on Worksheet ---
mNameValue = xlSheet.cells(mnRowCntr,mnNameCol).VALUE

You should be able to modify the code to do whatever you want on a sheet-by-sheet manner.

Good Luck,
JRB-Bldr
 
Tamar and JRB,
Both thanks for yr help.
It gives me enough 'source'code to proceed with my app.
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top