Public Sub GetData(StrPath, DataRange, Des())
Dim ObjConn As Object, RS As Object, StrRequest As String
Set RS = CreateObject("ADODB.Recordset")
Set ObjConn = GetExcelConnection(StrPath)
StrRequest = "SELECT * From " & DataRange
RS.Open StrRequest, ObjConn, 3, 1
Des = TransArr(RS.Getrows)
RS.Close
Set ObjConn = Nothing
Set RS = Nothing
End Sub
Public Function GetExcelConnection(ByVal Path As String)
Dim StrConn As String, ObjConn As Object, Pro As String, Ext As String
Set ObjConn = CreateObject("ADODB.Connection")
Pro = "Provider=Microsoft.ACE.OLEDB.12.0;"
Ext = ";Extended Properties=""Excel 8.0;"
StrConn = Pro & "Data Source=" & Path & Ext & "HDR=No" & ";IMEX=1"";"
ObjConn.Open StrConn
Set GetExcelConnection = ObjConn
End Function
Public Function TransArr(sArr As Variant) As Variant
Dim TmpArr As Variant, x As Long, y As Long
ReDim TmpArr(UBound(sArr, 2), UBound(sArr, 1))
For x = 0 To UBound(sArr, 2)
For y = 0 To UBound(sArr, 1)
TmpArr(x, y) = sArr(y, x)
Next y
Next x
TransArr = TmpArr
End Function