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

Thread: browse to open file open file

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Ontario, Canada
    Posts
    337
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is there a way I can have my macro run and give me the option to browse for a specific file.

    I have my macro setup to import a text file, I want to be able to make it user friendly so I can share it with other users with out having to correct the path in the code each time.

    the text file might also be named differently but contains the same data.

    Thanks in advance

    Ziggy

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sure, take a look at the

    GetOpenFileName

    method, which returns the filename of the selected file, or False (I think) if canceled.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Ontario, Canada
    Posts
    337
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks! Thats great I found an example in the help file.

    Ziggy

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Ontario, Canada
    Posts
    337
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I can make the file open code work, but I am having difficulty in putting it in place of the existing code which finds a specific file name on my PC, then goes through the text import wizard and converts it to Excel.

    This is just a sample of the code(I don't have the file with me)

    Sub fileopen2()
    '
    ' fileopen2 Macro
    ' Macro recorded 3/21/2002

    '
    Workbooks.OpenText Filename:="C:My Documentsmytextfile.txt", Origin:=xlWindows _
    , StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
    , Space:=False, Other:=False, FieldInfo:=Array(1, 1)
    ActiveWorkbook.SaveAs Filename:="C:My Documentsdupes.xls", FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
    , CreateBackup:=False
    End Sub

    I want this macro to be portable so I can send it to other users who can just browse for the correct text file on their PC's, instead of correcting the path.

    Thanks

    Ziggy

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Location
    England, UK.
    Posts
    526
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Give this a go.....


    fileToOpen = Application _
    .GetOpenFilename("Text Files (*.txt), *.txt")
    If fileToOpen <> False Then

    Workbooks.OpenText fileToOpen, _ Origin:=xlWindows _
    , StartRow:=1,

    etc.

    End If

    Hope this helps,

    RET79



    [ This Message was edited by: RET79 on 2002-03-21 14:32 ]

  6. #6
    Board Regular
    Join Date
    Feb 2002
    Location
    Ontario, Canada
    Posts
    337
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks !!! I got it working at home so it should be ok at work

    This is a bonus thanks alot!

    Ziggy

  7. #7
    Board Regular
    Join Date
    Feb 2002
    Location
    Ontario, Canada
    Posts
    337
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks !!! I got it working at home so it should be ok at work

    This is a bonus thanks alot!

    Ziggy

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
  •