|
Private Sub 全部导出_Click()
Dim myFSO As New FileSystemObject
Dim myFolder As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim rs1 As New ADODB.Recordset, rs2 As New ADODB.Recordset
Dim sql1 As String, sql2 As String
Dim i As Long, j As Long
Dim myfile As String
myFolder = GetFolder
sql1 = "SELECT 业务员 FROM 结算 GROUP BY 业务员;"
rs1.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs1.RecordCount
myfile = rs1("业务员") & ".xls"
'每100个另选文件夹
If i Mod 100 = 0 Then
myFolder = GetFolder
End If
' '其实如文件很多,不如设一个编号的文件夹,比较方便,不用另选。如:
' If i Mod 100 = 0 Then
' myFolder = myFolder & i
' End If
If myFSO.FileExists(myFolder & "\" & myfile) = False Then
Call CreatE(myfile, myFolder)
End If
sql2 = "SELECT * FROM 结算 where 业务员='" & rs1("业务员") & "'"
rs2.Open sql2, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.Visible = True
Set xlBook = xlApp.Workbooks.Open(myFolder & "\" & myfile)
'导出主表
xlBook.Application.Sheets(1).Select
xlBook.Application.Range("A1").Value = "姓 名:"
xlBook.Application.Range("B1").Value = rs1("业务员")
xlBook.Application.Range("A2").Value = "回款日期"
xlBook.Application.Range("b2").Value = "厂名"
xlBook.Application.Range("c2").Value = "回款类别"
|
|