+ Reply to Thread
Results 1 to 2 of 2

FileName / Path Function Modification

Hybrid View

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    East Coast, England
    MS-Off Ver
    Excel 2010
    Posts
    44

    FileName / Path Function Modification

    Hello Peeps,

    I have the following code from a google search but i would like to know if it can be modified to peform the same fuction on multipul cells (the number of cells will vary).

    I use Application.GetOpenFilename to get the full path in to Row 1 then the below Function twice with a slight change to seperate the path and file name out in to Cells

    What i need is a way to do this on multipul paths e.g

    A1 = C:\Rich\Test\rich.xmsl
    A2 = C:\Testing\this\really\long\folder\name\test.xmsl
    A3 = C:\Blah\blah.xmsl

    You get the idea at the end of the macro i would like

    A1 = C:\Rich\Test\rich.xmsl
    B1 = C:\Rich\Test\
    C1 = rich.xmsl

    A2 = C:\Testing\this\really\long\folder\name\test.xmsl
    B2 = C:\Testing\this\really\long\folder\name\
    C2 = test.xmsl

    A3 = C:\Blah\blah.xmsl
    B3 = C:\Blah\
    C3 = blah.xmsl


    Any Help Greatly Appreciated.

    Function getafilename() As String
    
    Dim someFileName As Variant
    Dim folderName As String
    Dim i As Integer
    Const STRING_NOT_FOUND As Integer = 0
    
    'select a file using a dialog and get the full name with path included
    someFileName = Cells(1, 5) '("Text Files (*.txt), *.txt")
    
    If someFileName <> False Then
    
        'strip off the folder path
        folderName = vbNullString
        i = 1
    
        While STRING_NOT_FOUND < i
            i = InStr(1, someFileName, "\", vbTextCompare)  'returns position of the first backslash "\"
            If i <> STRING_NOT_FOUND Then
                folderName = folderName & Left(someFileName, i)
                someFileName = Right(someFileName, Len(someFileName) - i)
            Else 'no backslash was found... we are done
                getafilename = someFileName
    
            End If
        Wend
    
    Else
        getafilename = vbNullString
    End If
    
    End Function

  2. #2
    Registered User
    Join Date
    02-21-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    1

    Re: FileName / Path Function Modification

    Long Path Tool deals with long path files. It works well to copy or delete long path files.

+ 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. [SOLVED] How to extract filename from path\filename
    By mpan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-05-2013, 11:23 PM
  2. Using a wildcard in path (not filename) with Dir function
    By MaartenKoller in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-10-2013, 06:19 AM
  3. Replies: 3
    Last Post: 07-09-2012, 03:09 PM
  4. Find filename, path, document size, filename length and path length?
    By Laneyboggs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2010, 08:01 PM
  5. function: copy current path or filename to clipboard (XLS)
    By Markus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2006, 06:35 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