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.

UDF to Determine Worksheet Names in Excel Workbook

Keywords: 	 Determine Worksheet Names in Excel Workbook

;/////////////////////////////////////////////////////////////////////////;
;//  WINBATCH   - Determine Worksheet Names in Excel Workbook that is    /;
;//  (U)ser     - closed.  Uses ADO rather than Access.Application.      /;
;//  (D)efined  - UDF could be easily formatted to (a) look for a        /;
;//  (F)unction - particular sheet in a subdir (b) create database of    /;
;//             - workbooks and named sheets                             /;
;//                                                                      /;
;//  RETURNS    - tab-delimited list of worksheets in selected workbook  /;
;//                                                                      /;
;//  Stan Littlefield   - June 23, 2002                                  /;
;/////////////////////////////////////////////////////////////////////////;
#DefineFunction GetSheets(cFile)
sheets    = ""
cat       = ObjectOpen( "ADOX.Catalog" )
cConn     = StrCat( "Provider=MSDASQL.1;Data Source=Excel Files;Initial Catalog=",cFile )
cat.ActiveConnection = cConn
tbls      = cat.Tables
n         = tbls.count()
For i     = 0 To ( n-1 )
   tbl    = cat.Tables(i)
   ; NOTE: ADO returns sheetnames with $ appended, i.e. Sheet1 is Sheet1$
   sheets = ItemInsert( StrReplace(tbl.Name,"$",""), -1, sheets, @TAB )
Next
ObJectClose( cat )
BoxShut()
Return( sheets )
#EndFunction

cFile     = AskFilename( "Select Excel File", DirGet(), "XLS|*.XLS","*.XLS",1)
BoxOpen( "Searching WorkBook...",cFile )
sheets    = AskItemList( StrCat( "WorkSheets In ",cFile ), GetSheets( cFile ), @TAB, @UNSORTED, @SINGLE )

Exit

Article ID:   W15260
File Created: 2002:09:05:13:50:52
Last Updated: 2002:09:05:13:50:52