|
楼主 |
发表于 2014-8-11 22:05
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 335081548 于 2014-8-11 22:41 编辑
使用ADOX不打开工作簿获取工作表名
代码如下:
- Sub 使用ADOX不打开工作簿获取工作表名_雪山飞狐()
- Dim MyCat As Object, MyTbl As Object
- Dim MyBook As String, i As Integer, StrConn As String
- Set MyCat = CreateObject("ADOX.Catalog")
- Set MyTbl = CreateObject("ADOX.Table")
- MyBook = ThisWorkbook.FullName'工作簿完整路径和工作簿名及扩展名
- Select Case Application.Version * 1 '设置连接字符串,根据版本创建连接
- Case Is <= 11
- StrConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & MyBook
- Case Is >= 12
- StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MyBook & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- MyCat.ActiveConnection = StrConn
- Cells.ClearContents
- i = 2
- Range("A1:B1") = Array("查询出的名称", "处理后的名称")
- For Each MyTbl In MyCat.Tables
- Cells(i, 1) = MyTbl.Name
- Cells(i, 2) = Mid(MyTbl.Name, 1, Len(MyTbl.Name) - 1)
- i = i + 1
- Next
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|