adamjones112182
New Member
- Joined
- Jan 30, 2020
- Messages
- 24
- Office Version
- 2016
- Platform
- Windows
Good Morning,
I am trying to get this code to run and it will not, I get an error stating that User Defined Type Not Defined. I have been in reference and I thought I clicked the right reference point, but maybe I am wrong. ( Microsoft ActiveX Data Objects Recordset 6.0 Library
Sub GetData_From_Excel_Sheet()
Dim MyConnect As String
Dim Myrecordset As ADODB.Recordset
Dim MySQL As String
MyConnect = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
"Data Source:=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 12.0"
MySQL = " Select * From [SampleData$]" & _
" Where Region ='NORTH'"
Set Myrecordset = New ADODB.Recordset
Myrecordset.Open MySQL, MyConnect, adOpenStatic, adLockReadOnly
ThisWorkbook.Sheets.Add
ActiveSheet.Range("A2").CopyFromRecordset Myrecordset
With ActiveSheet.Range("A1:F1")
.Value = Array("region", "Market", "Branch_Number", _
"Invoice_Number", "Sales_Amount", "Contracted Hours")
.EntireColumn.AutoFit
End With
End Sub
I am trying to get this code to run and it will not, I get an error stating that User Defined Type Not Defined. I have been in reference and I thought I clicked the right reference point, but maybe I am wrong. ( Microsoft ActiveX Data Objects Recordset 6.0 Library
Sub GetData_From_Excel_Sheet()
Dim MyConnect As String
Dim Myrecordset As ADODB.Recordset
Dim MySQL As String
MyConnect = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
"Data Source:=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 12.0"
MySQL = " Select * From [SampleData$]" & _
" Where Region ='NORTH'"
Set Myrecordset = New ADODB.Recordset
Myrecordset.Open MySQL, MyConnect, adOpenStatic, adLockReadOnly
ThisWorkbook.Sheets.Add
ActiveSheet.Range("A2").CopyFromRecordset Myrecordset
With ActiveSheet.Range("A1:F1")
.Value = Array("region", "Market", "Branch_Number", _
"Invoice_Number", "Sales_Amount", "Contracted Hours")
.EntireColumn.AutoFit
End With
End Sub