7,785
社区成员




Const MAXN As Long=1000
Dim strarray(0 TO MAXN) as String
Option Explicit
Private Sub Command1_Click()
Dim cn As ADODB.Connection, rs As ADODB.Recordset, strFile As String
Set cn = New ADODB.Connection
strFile = Dir("c:\test\*.xls")
Do While strFile > ""
Debug.Print strFile & ":"
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test\" & strFile & ";Extended Properties=""Excel 8.0; HDR=Yes;IMEX=1"""
Set rs = cn.OpenSchema(adSchemaTables)
Do Until rs.EOF
If rs!Table_Type = "TABLE" Then Debug.Print vbTab & rs!Table_Name
rs.MoveNext
Loop
cn.Close
strFile = Dir()
Loop
Set rs = Nothing
Set cn = Nothing
End Sub
结果新建 Microsoft Excel 工作表.xls:
Sheet1$
Sheet2$
Sheet3$
test.xls:
工作表1$
工作表2$
工作表3$
Dim XlApp As New Excel.Application
Dim XLWorkBook As New Excel.Workbook
Dim fn as String
Dim n As Long
XlApp.Visible=False
for n=1 to 100
fn=App.Path & "\"+CStr(n)+".xls"
Set XLWorkBook = XlApp.Workbooks.Open(fn)
For each in XLWorkBook.Worksheet in XLWorkBook.Sheets
debug.print fn;"+";XLWorkBook.Sheet.Name
Next
Set XLWorkBook=Nothing
XlApp.Close
next n