TMShucks
Active Member
- Joined
- Jan 10, 2011
- Messages
- 380
I got the following code from this forum, courtesy of Juan Pablo González, MrExcelMVP.
I'm trying to use this code with an .xlsm file in Excel 2007.
However, I get a "Run-time error '-2147467259 (80004005)': External table is not in the expected format."
If I try changing "Extended Properties=Excel 8.0;" to "Extended Properties=Excel 12.0;", I get a "Run-time error '-2147467259 (80004005)': Could not find installable ISAM."
I have references to
Microsoft ActiveX Data Objects 6.1 Library and
Microsoft ADO Ext. 6.0 for DDL and Security
If I save the .xlsm file as an .xls file, the code will work. I'm hoping this is something simple as, otherwise, it's just what I'm looking for.
Regards, TMS
http://www.mrexcel.com/forum/excel-...es-closed-workbook-post216171.html#post216171
I'm trying to use this code with an .xlsm file in Excel 2007.
However, I get a "Run-time error '-2147467259 (80004005)': External table is not in the expected format."
If I try changing "Extended Properties=Excel 8.0;" to "Extended Properties=Excel 12.0;", I get a "Run-time error '-2147467259 (80004005)': Could not find installable ISAM."
I have references to
Microsoft ActiveX Data Objects 6.1 Library and
Microsoft ADO Ext. 6.0 for DDL and Security
If I save the .xlsm file as an .xls file, the code will work. I'm hoping this is something simple as, otherwise, it's just what I'm looking for.
Regards, TMS
http://www.mrexcel.com/forum/excel-...es-closed-workbook-post216171.html#post216171
The following is a modification from the following post:
http://makeashorterlink.com/?U3C856C54 Note: the short link no longer works
It returns a collection, not an array, due to the option of "repeated" names when there is a print area setup.
I tried using the GET.WORKBOOK(1, ...) XLM macro as well, but a) doesn't work well in <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>, and b) doesn't work with closed workbooks.
Code:
[FONT=Courier][COLOR=#333333][COLOR=#00008B]Option[/COLOR] [COLOR=#00008B]Explicit[/COLOR]
[COLOR=#00008B]Function[/COLOR] GetSheetsNames(WBName [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR]) [COLOR=#00008B]As[/COLOR] Collection
****[COLOR=green]'Needs a reference to:[/COLOR]
****[COLOR=green]'Microsoft ActiveX Data Object X.X Library[/COLOR]
****[COLOR=green]'Microsoft ADO Ext. X.X for DLL and Security[/COLOR]
****
****[COLOR=#00008B]Dim[/COLOR] objConn [COLOR=#00008B]As[/COLOR] ADODB.Connection
****[COLOR=#00008B]Dim[/COLOR] objCat [COLOR=#00008B]As[/COLOR] ADOX.Catalog
****[COLOR=#00008B]Dim[/COLOR] tbl [COLOR=#00008B]As[/COLOR] ADOX.Table
****[COLOR=#00008B]Dim[/COLOR] sConnString [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR]
****[COLOR=#00008B]Dim[/COLOR] sSheet [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR]
****[COLOR=#00008B]Dim[/COLOR] Col [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]New[/COLOR] Collection
****
****sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
******************"Data Source=" & WBName & ";" & _
******************"Extended Properties=Excel 8.0;"
****[COLOR=#00008B]Set[/COLOR] objConn = [COLOR=#00008B]New[/COLOR] ADODB.Connection
****objConn.[COLOR=#00008B]Open[/COLOR] sConnString
****[COLOR=#00008B]Set[/COLOR] objCat = [COLOR=#00008B]New[/COLOR] ADOX.Catalog
****[COLOR=#00008B]Set[/COLOR] objCat.ActiveConnection = objConn
****[COLOR=#00008B]For[/COLOR] [COLOR=#00008B]Each[/COLOR] tbl [COLOR=#00008B]In[/COLOR] objCat.Tables
********sSheet = tbl.Name
********sSheet = Application.Substitute(sSheet, "'", "")
********sSheet = Left(sSheet, InStr(1, sSheet, "$", 1) - 1)
********[COLOR=#00008B]On[/COLOR] [COLOR=#00008B]Error[/COLOR] [COLOR=#00008B]Resume[/COLOR] [COLOR=#00008B]Next[/COLOR]
********Col.Add sSheet, sSheet
********[COLOR=#00008B]On[/COLOR] [COLOR=#00008B]Error[/COLOR] [COLOR=#00008B]GoTo[/COLOR] 0
****[COLOR=#00008B]Next[/COLOR] tbl
****[COLOR=#00008B]Set[/COLOR] GetSheetsNames = Col
****objConn.[COLOR=#00008B]Close[/COLOR]
****[COLOR=#00008B]Set[/COLOR] objCat = [COLOR=#00008B]Nothing[/COLOR]
****[COLOR=#00008B]Set[/COLOR] objConn = [COLOR=#00008B]Nothing[/COLOR]
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Function[/COLOR]
[COLOR=#00008B]Sub[/COLOR] Test()
****[COLOR=#00008B]Dim[/COLOR] Col [COLOR=#00008B]As[/COLOR] Collection, Book [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR], i [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Long[/COLOR]
****Book = "C:\Your path\Your file.xls"
****[COLOR=#00008B]Set[/COLOR] Col = GetSheetsNames(Book)
****[COLOR=#00008B]For[/COLOR] i = 1 [COLOR=#00008B]To[/COLOR] Col.Count
********MsgBox Col(i)
****[COLOR=#00008B]Next[/COLOR] i
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Sub
[/COLOR][/COLOR][/FONT]