Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Reading sheet names in closed workbooks - Is it possible?

Say there are a number of workbooks in a folder. Each sheet's name in
each workbook is an employee's name.
Is it possible to have another workbook in that folder with code that
can compile a list of employee's names (sheet names) and workbook
names.

Or, do the workbooks all have to be opened before code can compile such
a list.

Any ideas?

Ken Johnson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Reading sheet names in closed workbooks - Is it possible?


Tom Ogilvy wrote:
Jake Marx has been a good source on using ADOX to do this:

http://tinyurl.com/yuvqox

--
Regards,
Tom Ogilvy



Thanks Tom.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Reading sheet names in closed workbooks - Is it possible?

Hi Tom,

I tried this one...

Sub GetSheetNames(rsFilePath As String)
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table

Set cat = New ADOX.Catalog

cat.ActiveConnection = "Provider=MSDASQL.1;Data Source=" _
& "Excel Files;Initial Catalog=" & rsFilePath
For Each tbl In cat.Tables
If Right$(tbl.Name, 1) = "$" Then _
MsgBox Left$(tbl.Name, Len(tbl.Name) - 1)
Next tbl

Set cat = Nothing
End Sub

Nothing happened.

I discovered that the conditional test...

If Right$(tbl.Name, 1) = "$" Then

failed for every sheet because, for example, with a sheet named John
Smith...

Right$(tbl.Name, 1) = "'", not "$", because tbl.Name = "'John Smith$'",
not "John Smith$".

So, I've had to amend the code to accommodate the leading and trailing
apostrophes...

If Right(tbl.Name, 2) = "$'" Then _
MsgBox Mid(tbl.Name, 2, Len(tbl.Name) - 3)

Any idea as to why I would get these apostrophes that Jake's code
doesn't expect?

Also, Right and Right$ work the same don't they?

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Reading sheet names in closed workbooks - Is it possible?


Thanks Tom and Martin,

It all makes sense now!
So I'll have to extend the code to cater for sheet names with and
without spaces.

Ken Johnson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading values from a closed workbook Graham F New Users to Excel 6 July 28th 08 03:32 PM
Reading from a closed workbook WannaBeExceller Excel Programming 1 February 22nd 06 04:50 PM
Return Sheet Names from Closed Workbook crispbd[_38_] Excel Programming 1 November 24th 04 05:46 PM
Reading from a closed file. aking1987 Excel Worksheet Functions 1 November 15th 04 03:48 PM
Reading Sheet Names/Index from closed file using Biff8. keepITcool Excel Programming 16 November 5th 04 01:48 PM


All times are GMT +1. The time now is 01:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"