|
- Sub test1() '没认真看,再试试,不对就算了
- Dim Conn As Object, SQL As String, p As String, f As String, i As Integer
- Range("A1").CurrentRegion.Offset(1, 1).ClearContents
- Application.ScreenUpdating = False
- Set Conn = CreateObject("ADODB.Connection")
- Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
- p = ThisWorkbook.Path & "\导出数据\"
- For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
- f = Dir(p & Cells(i, 1).Value & ".xls*")
- If Len(f) Then
- SQL = "SELECT 费款所属期,参保单位名称 FROM [Excel 12.0;Database=" & p & f & "].[$C1:G2]"
- Cells(i, 2).CopyFromRecordset Conn.Execute(SQL)
- End If
- Next
- Conn.Close
- Set Conn = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
|