Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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