VBA Import Text File

  • I am importing large debug log text files in to excel. I trawled the threads and couldn't find a suitable solution to this one. The files are often more than 65536 rows and I have got the code for importing more than 65536 rows from the MS Website. However, this only does a straight import and puts all the data in the first cell in each row. I have my own code for importing the text as delimited values in to seperate cells but this doesn't deal with importing files larger than 65536 rows. Therefore I need a way of marrying the two together. I've done some VBA in Access before but am pretty rusty. Finally if somewhere can finish it off by getting the code to prompt for a file to import ( which includes a browse feature to select the file ) I would be most grateful. Many thanks for any help.

    Code is as follows:

    From MS:

  • Sferical,

    Is this the code that you are after:

    Sub GetFileNameExample()
        Dim fNameAndPath As Variant
        fNameAndPath = Application.GetOpenFilename _
                   (FileFilter:="Text Files (*.txt), *.txt", _
                    Title:="Select File To Be Opened")
        If fNameAndPath = False Then _
                          Exit Sub
        MsgBox fNameAndPath
    End Sub


  • Or is this what you are after?

  • Imbuzi, thanks for that. It looks like that will sort the file opening issue. Where abouts would I place this in the existing code?

    Can anyone else help to combine the first two bits of code so that I can import large delimited text files.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!