+ Reply to Thread
Results 1 to 5 of 5

Extracting a file path from a cell in VBA

  1. #1
    Registered User
    Join Date
    05-21-2012
    Location
    Indy
    MS-Off Ver
    Excel 2010
    Posts
    33

    Extracting a file path from a cell in VBA

    I'm writing a program that will be ran on a network, and my code pulls files from my computer and outputs files to the same directory. Can someone give me some sample code that can extract a file path in a cell without opening up a file dialogue box?

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Extracting a file path from a cell in VBA

    Can someone give me some sample code that can extract a file path in a cell without opening up a file dialogue box?
    I'll assume that no one else so far has attempted to give an answer because what you're asking sounds so simple that they assume that there must be more to it.

    I can only assume that you need something more than:

    Please Login or Register  to view this content.
    If there was a file path in cell A1, now there is a file path in the variable sPath.

  3. #3
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Extracting a file path from a cell in VBA

    I think he wanted the folder file path...

    Try this, I've used this to pass the "path" to a string variable. You could easily output the string variable to a cell in the workbook if that is what you want to do. Take advantage of the difference in the fullname and name of a workbook.

    myPath = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name))


    You could also assign the value directly to a cell if you're some kind of extra variable hating type

    thisworkbook.worksheets("someSheet").cells(i,j).value = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name))
    Last edited by GeneralDisarray; 05-30-2012 at 10:07 AM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    05-21-2012
    Location
    Indy
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Extracting a file path from a cell in VBA

    Quote Originally Posted by StevenM View Post
    I'll assume that no one else so far has attempted to give an answer because what you're asking sounds so simple that they assume that there must be more to it.

    I can only assume that you need something more than:

    Please Login or Register  to view this content.
    If there was a file path in cell A1, now there is a file path in the variable sPath.
    This was exactly what I needed! I knew it had to be pretty simple, but I'm EXTREMELY knew to programming with VBA. Thanks for your help!

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Extracting a file path from a cell in VBA

    To: GeneralDisarray,

    In that case why not:

    Please Login or Register  to view this content.

+ 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.6.0 RC 1