|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Access VBA代码- '++++++++++++++++++++++++++++++++++++++++
- '+ Access2Excel Created by taller@ExcelHome
- '+ 代码运行的前提:
- '+ 1. 在打开的Access数据库中添加并运行下述代码
- '+ 2. 请确保Access数据库中每个表中数据不超过Excel工作表的容量
- '+ 3. 导出到相同目录下的 Access.xls中
- '+ 4. 错误处理代码可以自行扩展(如:工作簿中已经存在和Access表相同名称的工作表)
- '++++++++++++++++++++++++++++++++++++++++
- Sub Access2Excel()
- Dim db As Database, Tabl As TableDef, TableName As String
- Dim strFullPath As String, strDir, strExcelFile As String
- Set db = DBEngine.Workspaces(0).Databases(0)
- strFullPath = db.Name
- strDir = Split(strFullPath, "")
- strDir(UBound(strDir)) = "Access.xls"
- strExcelFile = Join(strDir, "")
- For Each Tabl In db.TableDefs
- TableName = Tabl.Name
- If InStr(1, TableName, "MSys") = 0 Then
- db.Execute _
- "SELECT * INTO [Excel 8.0;DATABASE=" _
- & strExcelFile & "].[" & TableName & "] FROM " _
- & "[" & TableName & "]"
- End If
- Next
- End Sub
复制代码
[ 本帖最后由 taller 于 2010-10-31 22:06 编辑 ] |
|