(分享)获取其它工作簿工作表名
热度 2已有 628 次阅读2008-11-19 12:11
|个人分类:EXCEL实例
方法一:
Private Sub GetSheetName()
Set VBEXCEL = CreateObject("Excel.Application")
VBEXCEL.Workbooks.Open CurrentProject.Path & "\表名.xls"
For i = 1 To VBEXCEL.Worksheets.Count
Debug.Print VBEXCEL.Worksheets(i).Name
Next
VBEXCEL.Quit
Set VBEXCEL = Nothing
End Sub
方法二:
Sub Main()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\Book1.xls;DefaultDir=C:\"
Set rst = cnn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, Empty))
While Not rst.EOF
Debug.Print rst!TABLE_NAME
rst.MoveNext
Wend
Set rst = Nothing
Set cnn = Nothing
End Sub