azizrasul
Well-known Member
- Joined
- Jul 7, 2003
- Messages
- 1,304
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
I get no errors when running this code, however the data in the text file does not appear in Sheet1, which is the only sheet in the workbook?
I also want to refresh the csv file in case the data has changed.
I also want to refresh the csv file in case the data has changed.
Code:
Sub Button1_Click()
Dim ws As Worksheet, destRng As Range, fileName As String
fileName = "C:\Users\RasulA\Documents\Personal\Book1.csv"
Set destRng = Range("A1")
Set ws = ActiveSheet
With ActiveSheet.QueryTables.Add(Connection:="text; & C:\Users\RasulA\Documents\Personal\Book1.csv", Destination:=Application.Cells(1, 1))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 852
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
'Select your delimiter - selected below for Comma
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileTrailingMinusNumbers = True
'This will refresh the query
'ws.QueryTables.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Save
End Sub