Created
December 31, 2018 05:30
-
-
Save ndthanh/c8277d80255238050de770806b8c9066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function GetConnXLS(ByVal cFileName As String, _ | |
Optional ByVal InformErrMSG As Boolean = False) | |
On Error GoTo errHandling: | |
'Open ADO connection to excel workbook | |
Dim oConn As Object | |
Dim Ext As String, ConnStr As String | |
Set oConn = CreateObject("ADODB.Connection") | |
ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ | |
"Data Source=" & cFileName & ";" & _ | |
"Extended Properties=""Excel 12.0;HDR=Yes;"";" | |
oConn.Open ConnStr | |
Set GetConnXLS = oConn | |
errHandling: | |
If Err.Number <> 0 Then | |
Set oConn = Nothing | |
If InformErrMSG Then | |
MsgBox "GetConnXLS" & ": " & Err.Number & " " & Err.Description, vbCritical | |
End If | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment