|
- Sub test1() '好吧,更新一下,提供更多选择……
-
- 'Dim Conn As New ADODB.Connection, rs As New ADODB.Recordset
- Dim Conn As Object ', rs As Object
- Dim wkb As Workbook, wks As Worksheet
- Dim strConn As String, strSQL As String, SQL As String, s As String, i As Long
- Dim p As String, f As String, strPath As String
-
- DoApp False
-
- strPath = ThisWorkbook.Path
-
- With Application.FileDialog(msoFileDialogFolderPicker)
- .InitialFileName = Left(strPath, InStrRev(strPath, "\"))
- If .Show Then p = .SelectedItems(1) Else GoTo Line0
- End With
- If Right(p, 1) <> "\" Then p = p & "\" '此为选择 源文件 路径
-
-
- 'p = Left(strPath, InStrRev(Left(strPath, Len(strPath) - 1), "\")) & "源文件\" '这里直接指定 源文件 路径,适用于提供附件 文件夹结构
-
-
- strPath = strPath & "\" '若另存为工作簿,这里是另存路径
-
-
- 'Set rs = CreateObject("ADODB.Recordset")
- Set Conn = CreateObject("ADODB.Connection")
- s = "Excel 12.0;HDR=YES;Database="
- If Application.Version < 12 Then
- s = Replace(s, "12.0", "8.0")
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- Conn.Open strConn & strPath & "银行卡账户信息.xlsx"
-
- Set wkb = Workbooks.Open(strPath & "工资银行卡明细.xlsx", 0)
- With wkb
- For i = .Worksheets.Count To 2 Step -1
- .Worksheets(i).Delete
- Next
- Set wks = .Worksheets(1)
- End With
-
-
- SQL = "SELECT 收款人姓名,收款账号,`收款银行(必填)` AS 所属银行 FROM [$A1:C] WHERE 收款人姓名 IS NOT NULL"
- strSQL = "SELECT 员工工号,员工姓名,职位,实发工资 FROM [" & s & p & "[.f]].[门店工资汇总$A3:BR] WHERE 员工姓名 IS NOT NULL"
- strSQL = "SELECT a.员工工号,a.员工姓名,a.职位,b.收款账号,b.所属银行,a.实发工资 FROM (" & strSQL & ") a LEFT JOIN (" & SQL & ") b ON a.员工姓名=b.收款人姓名"
-
- f = Dir(p & "*.xls*")
- While Len(f)
- If ThisWorkbook.FullName <> p & f Then
-
- '''''''''''''''''''''''''''''''''''''''''''''''''''下段另存为 工作簿
- ' wks.Copy
- ' With ActiveWorkbook
- ' With .Worksheets(1)
- ' .Range("A4").CopyFromRecordset Conn.Execute(Replace(strSQL, "[.f]", f))
- ' .Name = Split(f, ".xls")(0)
- ' End With
- ' .SaveAs strPath & Split(f, ".xls")(0), 51
- ' .Close
- ' End With
- '''''''''''''''''''''''''''''''''''''''''''''''''''上段另存为 工作簿
-
-
- '''''''''''''''''''''''''''''''''''''''''''''''''''下段在原工作簿中创建新 工作表
- With wkb
- wks.Copy After:=.Worksheets(.Worksheets.Count)
- With .Worksheets(.Worksheets.Count)
- .Range("A4").CopyFromRecordset Conn.Execute(Replace(strSQL, "[.f]", f))
- .Name = Split(f, ".xls")(0)
- End With
- End With
- '''''''''''''''''''''''''''''''''''''''''''''''''''上段在原工作簿中创建新 工作表
-
- End If
- f = Dir
- Wend
-
- wkb.Close True
- Set wks = Nothing
- Set wkb = Nothing
- Conn.Close
- Set Conn = Nothing
- Line0:
- DoApp
- Beep
- End Sub
- Function DoApp(Optional b As Boolean = True)
- With Application
- .ScreenUpdating = b
- .DisplayAlerts = b
- .Calculation = -b * 30 - 4135
- End With
- End Function
复制代码 |
|