[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Retrieving Excel Worksheets Names

Posted on 2004-11-26
4
Medium Priority
?
359 Views
Last Modified: 2010-04-05
Does anybody know how to obtain a list of all the worksheet names in an excel workbook?

0
Comment
Question by:petelazell
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 1000 total points
ID: 12679950
var
  XL: Variant;
  i: integer;
begin
  XL := CreateOleObject('Excel.Application');
  ... //open the excel file here

  // adds the sheets names to a memo
  for i := 1 to XL.ActiveWorkbook.WorkSheets.Count do begin
    Memo1.Lines.Add(XL.ActiveWorkbook.WorkSheets[i].Name);
  end;

  ...

Regards, Geo
0
 

Author Comment

by:petelazell
ID: 12680087
Worked a treat, thanks!!!
0
 
LVL 17

Expert Comment

by:geobul
ID: 12680266
You are welcome :-)
0
 
LVL 17

Expert Comment

by:geobul
ID: 12680982
Just one more thing I've forgotten: it's a good idea to check whether the workbook contains sheets before getting their names:

if XL.ActiveWorkbook.WorkSheets.Count > 0 then begin
 for i := 1 to XL.ActiveWorkbook.WorkSheets.Count do begin
    Memo1.Lines.Add(XL.ActiveWorkbook.WorkSheets[i].Name);
  end;
else ShowMessage('There are no sheets in the workbook.');
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question