|
解决方法,全部按照文本对待,最后再把应该是数字的文本变回数字:
- Sub ado联合查询()
- Dim cnn As Object, SQL$, f$, p$, m%, 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
- Set cnn = CreateObject("adodb.connection")
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls")
- While f <> ""
- If f <> ThisWorkbook.Name Then
- m = m + 1
- If m = 1 Then
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='excel 8.0;imex=1';Data Source=" & p & f
- SQL = "select * from [工作表目录$]"
- Else
- SQL = SQL & " union all select * from [Excel 8.0;imex=1;Database=" & p & f & "].[工作表目录$] "
- End If
- End If
- f = Dir()
- Wend
- [a1].CurrentRegion.Offset(1).ClearContents
- [a2].CopyFromRecordset cnn.Execute(SQL)
- With ActiveSheet.UsedRange
- .Value = .Value
- End With
- cnn.Close
- Set cnn = Nothing
- Set objWMI = Nothing
- End Sub
复制代码 |
|