|
demonwzr 发表于 2013-1-11 08:33
谢谢,十分感谢,要是我想收集个人表中更多数据的话,需要改的是哪段话,是不是If Len(SQL) Then SQL = S ...
假设你想收集的数据是:姓名 结论 血压- Private Sub Workbook_Open()
- Dim cnn As Object, SQL$, MyPath$, MyFile$, m&, n&, t$
- Application.ScreenUpdating = False
- Sheets("Sheet1").Activate
- Sheets("Sheet1").UsedRange.Offset(2).ClearContents
- Set cnn = CreateObject("ADODB.Connection")
- MyPath = ThisWorkbook.Path & ""
- MyFile = Dir(MyPath & "*.xls")
- Do While MyFile <> ""
- If MyFile <> ThisWorkbook.Name Then
- n = n + 1
- If n = 1 Then
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no';Data Source=" & MyPath & MyFile
- Else
- t = "[Excel 8.0;hdr=no;Database=" & MyPath & MyFile & "]."
- End If
- m = m + 1
- If m > 49 Then
- Range("b65536").End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)
- m = 1
- SQL = ""
- End If
- If Len(SQL) Then SQL = SQL & " union all "
- SQL = SQL & "select top 1 '" & Replace(MyFile, ".xls", "") & "',(select f1 from " & t & "[Sheet1$b13:b13]),(select f1 from " & t & "[Sheet1$d9:d9]) from " & t & "[Sheet1$]"
- End If
- MyFile = Dir()
- Loop
- If Len(SQL) Then Range("b65536").End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)
- [a3] = 1
- m = [b65536].End(xlUp).Row
- If m > 3 Then [a3].AutoFill Destination:=Range("A3:A" & m), Type:=xlFillSeries
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|