+ Reply to Thread
Results 1 to 6 of 6

Value of Last Folder of File Path

  1. #1
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Value of Last Folder of File Path

    Hi all

    When browsing for a file with VBA, how can I read the file name of the document selected:

    Example 1:
    C:\Australia\Sydney\Summary.zip
    --> I would like the code to return "Summary.zip"


    Example 2:
    C:\New Zealand\Auckland\2019\Final Slides\Presentation.zip
    --> I would like the code to return "Presentation.zip"

    The number of folders and string lenght can, as you see in my example, vary.

    Any help is appreciated.

    Thanks
    FD

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Value of Last Folder of File Path

    Use "\" as delimiter and split string.

    Ex:
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Value of Last Folder of File Path

    THe document selected? Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Value of Last Folder of File Path

    Thanks, that worked...
    but what is X in this case? like a collection?

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Value of Last Folder of File Path

    I used x as variant, which is implicitly assigned array from split function.

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Value of Last Folder of File Path

    I use the following functions for extracting parts of file paths:
    Please Login or Register  to view this content.
    In your case:
    Please Login or Register  to view this content.
    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [Path location and Document macro]Require File , Folder and sub-folder path creator macro
    By Nitish Shrestha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2017, 02:23 AM
  2. [SOLVED] How to select a file instead of selecting the file's destination path/folder
    By dedark05 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-30-2016, 10:17 PM
  3. Replies: 2
    Last Post: 12-29-2015, 04:19 AM
  4. Choosing folder path (instead of file path) in VBA
    By sminter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2014, 08:50 PM
  5. Code to list the folder path and sub folder path of a specific file
    By kalai1587 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2013, 03:51 AM
  6. [SOLVED] Save As Dialog Box - Default Path and File Name, User Selects Sub Folder from Default Path
    By christenprochaska in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2012, 05:17 PM
  7. Specified folder path to select file path
    By JayEmTee91 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2012, 10:38 AM

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