Consulting

Results 1 to 7 of 7

Thread: Solved: Change file path name

  1. #1
    VBAX Contributor JeffT's Avatar
    Joined
    Oct 2004
    Location
    Maidenhead, Nr London UK
    Posts
    105
    Location

    Solved: Change file path name

    Hi

    I'm trying to open a file (Susa Charts.xls) which is in the same folder as the open file (Susa Spreadsheet). When in use it could be anywhere on any computer but will be stored in the same folder. I'm looking to use:-

    Dim Path As String

    Path = ActiveWorkbook.FullName

    to get the path to the spreadsheet. It shows something like:-

    C:\Documents and Settings\My Documents\Work\Susa Spreadsheet.xls

    Then cut the name "Susa Spreadsheet.xls", though this name may have changed, so want to cut it back to the first "\". I can then use "&" to add back the name "Susa Chart.xls" to the Path so it will open using

    Workbooks.Open (Path)

    Path = C:\Documents and Settings\My Documents\Work\Susa Charts.xls

    It may be that the "Susa Chart" name may change but I'll cross that bridge later. I'll put in a file selection dialog box if the path doesn't work.

    I think I need something like Trim & Len but have searched and can't find it working with File paths. Perhaps this is not the best way to do it but it's the only way i can think of. If there's an easier way of opening a file in the same folder I'll be happy

    Hope you can help

    Thanks in anticipation

    Jeff

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Pth = ActiveWorkbook.Path[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Contributor JeffT's Avatar
    Joined
    Oct 2004
    Location
    Maidenhead, Nr London UK
    Posts
    105
    Location
    Thanks mdmackillop

    I knew it'd be simple. I need to practise more

    Best wishes

    Jeff

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Happy to help. Also, look at the Split function. Very useful for extracting data from such strings.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Contributor JeffT's Avatar
    Joined
    Oct 2004
    Location
    Maidenhead, Nr London UK
    Posts
    105
    Location
    Yes had a quick look in VBA help thanks. The problem is always knowing what to look for.

    Just trying to find out how to set the thread to solved. I used to know how but haven't been here for a while. Pity there's not a button.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It's under Thread Tools if you don't use Chrome.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Contributor JeffT's Avatar
    Joined
    Oct 2004
    Location
    Maidenhead, Nr London UK
    Posts
    105
    Location
    I was in Chrome, switched to IE thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •