Hi all,
Want to import a text file in excel via macro, however I need it to do two things - first I want to select a text file (as the name changes every day) & secondly I want it to be imported with delimiters '|'.
Currently I have something as mentioned below, however the below code only provides me a dialog box and after selecting the right file, it opens it in excel sheet without any delimiters.
Kindly help.
Code:
Want to import a text file in excel via macro, however I need it to do two things - first I want to select a text file (as the name changes every day) & secondly I want it to be imported with delimiters '|'.
Currently I have something as mentioned below, however the below code only provides me a dialog box and after selecting the right file, it opens it in excel sheet without any delimiters.
Kindly help.
Code:
Code:
Sub txtfile()
Dim myfile
myfile = Application.GetOpenFilename("Txt files (*.txt), *.txt", , "Please select your file")
If myfile = False Then Exit Sub
Dim aData As String
aData = ""
Dim x As Long
x = 1
Open myfile For Input As #1
While Not EOF(1)
Input #1, aData
Range("A" & x).Value = aData
x = x + 1
Wend
Close #1
End Sub
Last edited: