Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I am playing with this concept to access data from a closed workbook. Because I am unfamiliar with this, and simply experimenting, I'm unsure if what I am trying to do (find the match of a value in the worksheet of the closed workbook) is even possible with this method. If it's possible, I'm clearly not understanding the contecxt well enough for which my code is incorrect. The line in red is leaving me with an object required error. I assume rs.source isn't an object.
The hope is that if I can get the row (match value) from the data in the closed workbook, I can populate a series of cells in the active workbook without having to rely on 167 different vlookup formulae.
Looking for input from the good folk here to advise whether I'm on the wrong path to success with this method.
Rich (BB code):
Sub StaffOnChange()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim staffPath As String
Dim staffFile
Dim staffOpn As String
Dim stfRow As Long
Set wsHold = Application.ThisWorkbook.Worksheets("Hold")
staffPath = "D:\WSOP 2020\SupportData\"
staffFile = wsHold.Range("N1")
staffOpn = staffPath & staffFile
Set cn = New ADODB.Connection
cn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & staffOpn & ".xlsm;" & _
"Extended Properties='Excel 12.0 Macro;HDR=YES';"
cn.Open
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.Source = "SELECT * from [MASTER$]"
rs.Open
stfRow = Application.WorksheetFunction.Match(wsHold.Range("C3"), rs.Source.Columns(1), 0)
rs.Close
cn.Close
End Sub
The hope is that if I can get the row (match value) from the data in the closed workbook, I can populate a series of cells in the active workbook without having to rely on 167 different vlookup formulae.
Looking for input from the good folk here to advise whether I'm on the wrong path to success with this method.