I would like to post this thread (kinda different topic) regarding a reply in previous thread: https://www.excelforum.com/excel-pro...-database.html
How to use VBA to pull data into text file? I was able to use below code to pull data from MS SQL to excel sheet, however, sometimes there are multiple millions of records (or I don't want to make excel file size too large, just use a text file as data source), how can I modify the code and pull data into text file (using below folder path)?
From the text file, how can I use VBA (SELECT *** From Text_File Where ColumnName = ***) to pull data from text file to excel sheet?
Set Cn = CreateObject("ADODB.Connection")
Cn.Open ConnectionString
Set TestRs = CreateObject("ADODB.Recordset")
TestQuery = "Select * From Table_name"
TestRs.Open TestQuery, Cn
i = 0
For Each TestField In TestRs.Fields
WB.Sheets("Home").Cells(1, 1).Offset(, i) = TestField.Name
i = i + 1
Next
WB.Sheets("Home").Cells(2, 1).CopyFromRecordset TestRs
Set TestRs = Nothing
WBName = ThisWorkbook.Name
WBFullName = ThisWorkbook.FullName
FolderPath = Replace(WBFullName, WBName, "")
Bookmarks