+ Reply to Thread
Results 1 to 5 of 5

Changing An Absolute Path To A Relative Path

  1. #1
    Registered User
    Join Date
    07-19-2010
    Location
    Austria
    MS-Off Ver
    Excel 2003
    Posts
    20

    Arrow Changing An Absolute Path To A Relative Path

    hello

    i am running a VBA script which updates cells of all files in a given folder:
    Please Login or Register  to view this content.
    in A19, i am defining the path: i.e. C:\Documents\Files\Test

    however, this is an absolute path. let's say, the document which executes the macro is located in "Files", i just want to write "\Test", instead of entering the whole absolute path. Or let's say i want to update the cells in the folder above, i would like to write "..\"

    does anyone have some hints or tips on how to achieve this?
    any help would be very very much appreciated!
    Last edited by elgourmet; 08-03-2010 at 05:35 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Changin An Absolute Path To A Relative Path

    The code

    Please Login or Register  to view this content.
    Will return the file path of the workbook that is executing the code.

  3. #3
    Registered User
    Join Date
    07-19-2010
    Location
    Austria
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Changin An Absolute Path To A Relative Path

    thanks!! exactly what i wanted. works like a charm
    one more question though. how can i go one folder up?
    ..\Test works, but ..\ doesnt....

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Changin An Absolute Path To A Relative Path

    Add a little function to find the last occurence of a character within a string ...

    Please Login or Register  to view this content.
    Then use this to find the last back slash in the file path...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-19-2010
    Location
    Austria
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Changin An Absolute Path To A Relative Path

    very cool, thanks a lot!
    i just found out that ..\..\ works as well....
    but i will still use your code!

+ 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