+ Reply to Thread
Results 1 to 3 of 3

Open dialogue box and importing text files

  1. #1
    Registered User
    Join Date
    02-01-2006
    Posts
    60

    Open dialogue box and importing text files

    Hi,

    I am designing a macro that displays an Open dialogue box that asks a user to select a filename to open (in this case it’s a text file that I am importing into Excel)

    Application.Dialogs(xlDialogOpen).Show

    I need help with the code that comes after the file is selected and the user selects open. How to I ensure that the correct column settings (it's a fixed width import) are applied and the file continues to open?

    At present when the user selects “Open” the Import Wizzard come up. I need this part to be automated.

    I can do all of the above using an Importbox but would rather use the dialogue box.

    Hope this all makes sense!

    Regards
    Garry

  2. #2
    Dave Peterson
    Guest

    Re: Open dialogue box and importing text files

    dim myFileName as variant
    myfilename = application.getopenfilename("Text Files, *.txt")
    if myfilename = false then
    'user hit cancel
    exit sub '??
    end if

    Workbooks.OpenText Filename:=myFileName, .....

    If you record a macro when you open the text file, you'll see all the stuff that
    determines how each field is laid out.

    You can add this little portion to your code (so that your recorded filename can
    be removed).

    Gazzr wrote:
    >
    > Hi,
    >
    > I am designing a macro that displays an Open dialogue box that asks a
    > user to select a filename to open (in this case it’s a text file that I
    > am importing into Excel)
    >
    > Application.Dialogs(xlDialogOpen).Show
    >
    > I need help with the code that comes after the file is selected and the
    > user selects open. How to I ensure that the correct column settings
    > (it's a fixed width import) are applied and the file continues to
    > open?
    >
    > At present when the user selects “Open” the Import Wizzard come up. I
    > need this part to be automated.
    >
    > I can do all of the above using an Importbox but would rather use the
    > dialogue box.
    >
    > Hope this all makes sense!
    >
    > Regards
    > Garry
    >
    > --
    > Gazzr
    > ------------------------------------------------------------------------
    > Gazzr's Profile: http://www.excelforum.com/member.php...o&userid=31075
    > View this thread: http://www.excelforum.com/showthread...hreadid=513413


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    02-01-2006
    Posts
    60

    Thanks

    Excellent Dave,

    Thanks for your help. I should be able to work it out from here.

    Garry

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1