How to read data from a CSV file with a variable name to an excel workbook

Answered

I have a CSV file with a  variable name  “Daily Postings 18092015” but the date keeps changing every day when a new CSV file is created in my folder :S:My Documents.

Basically i need a VBA to open this CSV file using a notepad and copy the data to  my Excel workbook “Sample file.xlsm” Sheet “Postings” using the Delimiter Semicolon (;)

Since i am new to macro im finding it difficult to achieve this…Appreciate your help

Contributor Asked on July 12, 2015 in VBA: Basics.
Add Comment
1 Answer(s)
Best answer

Try this 

Sub Macro2() 
Filename = "Daily Postings " & Format(Date, "DDMMYY") & ".csv"
mypath = "TEXT;S:My Do*** ents\" & Filename ':S:My Do*** ents
With ActiveSheet.QueryTables.Add(Connection:= _
mypath, Destination:=Range _
("$a$1"))
.Name = "Import_User_Sample_en_3"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub 
 

Regards 

Mandeep baluja 

Top Contributor Answered on July 15, 2016.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.