Get the number of "sheets" in the Excel file

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi,

is it possible to get the number of "Sheets" in the Excel file, WITHOUT OPENING IT??

thanks in advance
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I'm not sure you can do this and get a precise sheet count without opening the workbook somewhere along the line. However, this code allows you to get a count of the number of worksheets (i.e. excluding charts, macro sheets, dialog sheets). In order for this code to run you must choose Tools, References from the VB editor and select:-


  • * Microsoft ActiveX Data Objects 2.n Library
    * Microsoft ADO Ext 2.n for DDL and Security

Once you've done that paste this code in a standard module:-

Code:
Sub GetSheetCount()
Dim oConn As New ADODB.Connection, adoxCat As ADOX.Catalog, strFileName As String

On Error GoTo ErrHandler:

'Put the file you want here
strFileName = "C:my documentsgeneral ledger pivot table.xls"

With oConn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Properties("Extended Properties").Value = "Excel 8.0"
    .Open strFileName
End With

Set adoxCat = New Catalog
Set adoxCat.ActiveConnection = oConn

MsgBox adoxCat.Tables.Count

Exit Sub

ErrHandler:
MsgBox Err.Description, , "An error occurred"
End Sub

HTH,
D
 
Upvote 0
thanks for your reply.
It worked and I could get worksheets information.

best wishes for you and your family.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top