My form will have a browse button, browse to file on your hard drive (a .txt) and then click open. Then on the form you will click the parse button and it will parse it out.
The easiest way to do this bit is to use the Application.GetOpenFile code
Once you get the text file you can use workbook.opentext
Search for these in the help file
Originally Posted by joshua310
Whats the easiest way to do this? Can I manually parse it and then look at the code w/ alt+F11?
Depends if there is a consequitve delimiter or fixed width not if there is you can use the TextToColumns property on your selected range but without knowing more i won't be able to be of too much more help
Following on from DavidCotts couts suggestion I have listed below a modified extract I have written to do just what you have indicated.
This is based on a form having two command buttons and a text box (you will also need to show the form).
Private Sub CommandButton1_Click()
Dim File As String
File = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Select Text File")
If File = "False" Then Exit Sub
If Dir(File) = "" Then
MsgBox File & " Not found !"
TextBox1 = File
Private Sub CommandButton2_Click()
Dim Text As String
If Dir(TextBox1) = "" Then
MsgBox File & "File Path & Name must be specied !"
Open TextBox1 For Input As #1 ' OPEN FILE FOR READING
Line Input #1, Text ' READ FIRST LINE
If Text <> "??" Then
MsgBox "File not compatable etc"
Do While Not EOF(FileNo)
'PARSE EACH FILE LINE HERE AND WRITE TO ACTIVE SHEET !!
Close #1 'CLOSE FILE
As indicated, information is available in the VBA Help files for both GetOpenFileName and the Open Method for reading a file on disk one line at a time.
Of course we do not know what procedure you require to parse each line.
This code also relies on the first line odf the file having a unique id to verifiy it is the correct type of file to be parsed!