Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: how to let user select filename when using macro

  1. #1
    Board Regular
    Join Date
    May 2002
    Posts
    50
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
    How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?

  2. #2
    Board Regular
    Join Date
    Apr 2002
    Posts
    115
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-07 11:13, joed wrote:
    I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
    How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?
    How about the GetOpenFileName method. Look under Help.

  3. #3
    MrExcel MVP Von Pookie's Avatar
    Join Date
    Feb 2002
    Location
    The act or process of locating.
    Posts
    13,686
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I got some help with something along those lines a little while back.

    Try adding this to your code instead of opening the one file:


    Which = Application.GetOpenFilename(MultiSelect:=True)
    'Which now contains an array of file names which you can enumerate through
    For I = 1 To UBound(Which)
    Workbooks.Open Which(I)



    This is what worked for me when I wanted it to bring up the open dialog box and let someone choose
    the files they want to open.

    Hope this helps,

    _________________
    ~*Kristy*~

    "Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam."


    [ This Message was edited by: Von Pookie on 2002-05-07 11:27 ]

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Posts
    76
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-07 11:13, joed wrote:
    I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
    How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?

    dim FileName as String
    FileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")

  5. #5
    Board Regular
    Join Date
    May 2002
    Posts
    50
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    how would I insert that code into this?

    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 05/07/2002 by joe
    '

    '
    Workbooks.OpenText FileName:="T:Mcdrpswg01

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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