+ Reply to Thread
Results 1 to 6 of 6

Thread: opening a text file

  1. #1
    Valued Forum Contributor
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Excel 2010 / Excel 2000 & 2003 for some at work
    Posts
    213

    opening a text file

    Hi there does anyone know if there is any code for opening a text file where the user can select which file. path to use ?
    Last edited by WasWodge; 07-16-2011 at 06:22 PM.
    Using Excel 2010
    Normally need to save as Excel 97-2003 for other colleagues

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  2. #2
    Valued Forum Contributor
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Excel 2010 / Excel 2000 & 2003 for some at work
    Posts
    213

    Re: opening a text file

    Hi again, I am just posting to say I have found a partial solution thanks to a thread I have found in this forum.
    http://www.excelforum.com/word-progr...es-wanted.html which recommended going to http://word.mvps.org/.
    On that site I found the code below which works for what I need (after I changed
    msoFileDialogFolderPicker
    to
    msoFileDialogFilePicker
    that is until I actually select a txt file, the box which starts off saying "open" changes to "ok" and when I click on it nothing appears to happen other than it moves on to
    MsgBox "You chose " & .SelectedItems(1)
    Does anyone have an idea how to amend it so it actually opens the file?

    Many thanks to JeanRage for the suggestion so far. Getting close (I think)

    With Application.FileDialog(msoFileDialogFolderPicker)
    
        .AllowMultiSelect = False
    
        If .Show <> 0 Then
    
            MsgBox "You chose " & .SelectedItems(1)
    
        Else
    
            MsgBox "Dialog cancelled"
    
        End If
    
    End With
    Using Excel 2010
    Normally need to save as Excel 97-2003 for other colleagues

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: opening a text file

    Sub snb()
      With Application.Dialogs(wdDialogFileOpen)
        .Name = "*.txt"
        .Show
      End With
    end sub
    or
    Sub snb()
      with Application.Dialogs(wdDialogInsertFile)
        .name="*.txt"
        .Show
      end with
    end sub
    Last edited by snb; 07-14-2011 at 06:01 PM.



  4. #4
    Valued Forum Contributor
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Excel 2010 / Excel 2000 & 2003 for some at work
    Posts
    213

    Re: opening a text file

    Thanks a million for that Snb. I have been scouring the web on and off for days looking for the correct syntax for this.
    Thats the last thing I needed to do on this macro.
    Thankfully I can go back to excel now until I get a word vba book.
    Cheers for the solution
    Using Excel 2010
    Normally need to save as Excel 97-2003 for other colleagues

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: opening a text file

    You don't have to look on Internet but in the helpfiles of Word's VBEditor .

    PS. Can you please enable PM's in this forum ? on ICQ no matches for you were found...
    Last edited by snb; 07-15-2011 at 03:44 AM.



  6. #6
    Valued Forum Contributor
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Excel 2010 / Excel 2000 & 2003 for some at work
    Posts
    213

    Re: opening a text file

    I did try using the search in the VBEditor originally but obviously I didn't use the correct search term. I have now typed in "application dialog" and now have lots of explanation. So thanks for that suggestion.

    I have now enabled PM's for all users (It was enabled for moderators and contacts).

    I didn't have it enabled because I thought in general it goes against the principle of a public forum but obviously in some cases others feel it is of use.

    I have also marked the thread as solved which I must have missed doing the other day. Apologises for that.
    Using Excel 2010
    Normally need to save as Excel 97-2003 for other colleagues

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

+ 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.2.0