|
- Sub OutputExcel(FileName As String)
- Dim myPath$, pathFile$
- myPath = CurrentDb.Name
- pathFile = Left(myPath, VBA.InStrRev(myPath, "")) & FileName & ".xls"
- DoCmd.OutputTo acOutputQuery, "Query2", "*.xls", pathFile
- End Sub
- Sub qryTest(PersonnelName As String)
- Dim dbs As Database, sql$
- sql = "Select * From NA Where 姓名='" & PersonnelName & "'"
- Set dbs = CurrentDb
- dbs.QueryDefs("Query2").sql = sql
- dbs.Close
- End Sub
- Sub OutputMain()
- Dim cnn, rst, sql$
- Set cnn = CreateObject("ADODB.Connection")
- Set rst = CreateObject("ADODB.Recordset")
- cnn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & CurrentDb.Name
- sql = "Select distinct 姓名 From NA"
- Set rst = cnn.Execute(sql)
- While Not rst.EOF
- Call qryTest(rst("姓名").Value)
- Call OutputExcel(rst("姓名").Value)
- rst.MoveNext
- Wend
- cnn.Close
- Set cnn = Nothing
- Set rst = Nothing
- End Sub
复制代码
NA.rar
(25.18 KB, 下载次数: 21)
详见附件! |
|