Results 1 to 4 of 4

Thread: Get full path to a file - vba
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,510
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Get full path to a file - vba

    This code here get me only the name of the selected file with its extension.

    Code:
    Sub GetFilePath()
    
    Set myFile = Application.FileDialog(msoFileDialogOpen)
    
    With myFile
    
    .Title ="Choose File"
    
    .AllowMultiSelect =False
    
    If.Show <>-1Then
    
    ExitSub
    
    EndIf
    
    FileSelected = Replace(.SelectedItems(1),.InitialFileName,"")
    
    EndWith
    
    MsgBox FileSelected
    
    EndSub
    
    When I change the line

    Code:
    FileSelected = Replace(.SelectedItems(1),.InitialFileName,"")

    To this
    Code:
    FileSelected =.SelectedItems(1)
    It adds the name of the file and it's extension to the path name.

    Now what I want to do is to get the path name only up to the last path separator . I have been digging around for a while now but can't seem to find out how to yet.

    I need a hand with that. Thanks
    There Is Always A Better Way

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Get full path to a file - vba

    Just use
    Code:
    FileSelected = .InitialFileName
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,510
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get full path to a file - vba

    Quote Originally Posted by Fluff View Post
    Just use
    Code:
    FileSelected = .InitialFileName

    Fantastic!!!

    This would have taken me years to figure out

    Have a nice time
    There Is Always A Better Way

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Get full path to a file - vba

    Glad to help & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

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
  •