Creating my first DB connection in VBA, Excel 2007
Posted on 2011-09-07
If this code throws no error, does that mean it's opening a connection? If so, to what?
It stops nicely at a breakpoint and exits the function gracefully.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "combo change to WS2"
Dim Myconnection As Connection
Dim Myrecordset As Recordset
Dim MyWorkbook As String
Set Myconnection = New Connection
Set Myrecordset = New Recordset
'Identify the workbook you are referencing
MyWorkbook = Application.ThisWorkbook.FullName
'Open connection to the workbook
Myconnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & MyWorkbook & ";" & _
"Extended Properties=Excel 8.0;" & _
"Persist Security Info=False"