Results 1 to 4 of 4
  1. #1
    buttonrd
    Guest

    Using Macro to Import Delimited Text File

    I would like to import a delimited text file with a macro that specifies everything necessary for the "text import wizard" yet allows the user to specify the file location. If I use the "application.findfile" statement, the macro user can select the file of their choice, but it immediately executes the text import wizard and does not allow the macro to specify the formatting. If I use the "opentext" method, I can specify all of the formatting for the text import wizard, but the method does not allow the user to select the file to be opened. Does anyone know of a way to write a macro that allows the user to browse for a file, yet specify the formatting for the text import wizard?

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    NJ, USA
    Posts
    239
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Using Macro to Import Delimited Text File

    I think what you need is something like the following:

    Public Sub ImportFile()
    Dim vntFilename As Variant

    '** Prompt user to select file to be imported...
    vntFilename = Application.GetOpenFilename(, , "Select File to Import")

    '** See if user pressed Cancel...
    If vntFilename = False Then
    Exit Sub
    End If

    Workbooks.OpenText Filename:=vntFilename, _
    StartRow:=1, ... etc ...

    End Sub

  3. #3
    buttonrd
    Guest

    Re: Using Macro to Import Delimited Text File

    Thanks so much for your reply. You are right. This is working great. Appreciate the help.

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using Macro to Import Delimited Text File

    I was looking at this code. I'm wondering if they open a textfile text.txt and I have Excel open already in j.xls, how can i got back to text.txt and do a saveas test.xls? thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •