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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Sheet Names 1

Status
Not open for further replies.

SqueakinSweep

Programmer
Joined
Jun 20, 2002
Messages
945
Location
GB
There are lots of great examples for Excel Automation, but all of them create a new excel sheet

What I want to know is, how to open an existing Excel File, and iterate through its sheets collection, and to be able to set the active sheet.

Thanks


Sweep
...if it works dont mess with it
 
SqueakinSweep

What I want to know is, how to open an existing Excel File, and iterate through its sheets collection

Code:
LOCAL oExcel as excel.application
LOCAL oWb
oExcel = CREATEOBJECT("excel.application")
oWb = oExcel.Workbooks.Open("c:\book2.xls")
nCount =owb.Sheets.Count
FOR i = 1 TO nCount
 ? oWb.sheets(i).name
ENDFOR
oExcel.Visible = .t.

and to be able to set the active sheet.

Code:
LOCAL oExcel as excel.application
LOCAL oWb
oExcel = CREATEOBJECT("excel.application")
oWb = oExcel.Workbooks.Open("c:\book2.xls")
nCount =owb.Sheets.Count
FOR i = 1 TO nCount
  IF oWb.sheets(i).name="Sheet3"
     owb.Sheets(i).Select
  endif
ENDFOR
oExcel.Visible = .t.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike

Many many thanks!

Sweep
...if it works dont mess with it
 
SqueakinSweep

Glad it works for you, thank you for the star!

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top