|
pppeeerrr 发表于 2014-5-29 14:38
赵老师,仔细测试您的附件以后,有些疑惑,详见附件! - Sub 宏1()
- Dim cnn As Object, SQL$, arr, i&
- Dim objWMI As Object
- Const HKEY_LOCAL_MACHINE = &H80000002
- Set objWMI = GetObject("winmgmts:\\.\root\default:StdRegProv")
- objWMI.SetDWORDValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "TypeGuessRows", 200
- arr = Sheets("各类列表").[a1].CurrentRegion
- MyPath = ThisWorkbook.Path & ""
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider = Microsoft.Ace.Oledb.12.0;Extended Properties =Excel 12.0;Data Source =" & MyPath & arr(1, 3)
- For i = 1 To UBound(arr)
- SQL = "select * from [Excel 12.0;imex=1;Database=" & MyPath & arr(i, 3) & ";].[" & arr(2, 2) & "$]"
- With Sheets(arr(i, 6))
- .Cells.ClearContents
- .[a1:b1] = Array("日期", "数值")
- .[a2].CopyFromRecordset cnn.Execute(SQL)
- With .UsedRange
- .Value = .Value
- End With
- End With
- Next
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|