Results 1 to 2 of 2

Thread: open .xls one directory up

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2004
    Posts
    16

    open .xls one directory up

    Hi,

    I have an excel file that needs to open another .xls file located one directory higher.
    This is the code i have so far:
    Code:
    Dim StrPath, StrName As String
    
    StrName = "file.xls"
    StrPath = ActiveWorkbook.Path & "\"
    
    ChDir (StrPath)
    
    ChDir ".."
    
    Workbooks.Open (StrName)
    The strange thing is that sometimes this code works perfect, but other times it returns an error saying it can't find the file. I'm not sure, but i think it has something to do with the systems memory.

    Anyone has an idea how i can put the new path (one folder higher after the ChDir ".." line) in a string so i can change:

    Code:
    Workbooks.Open (StrName)
    to
    Workbooks.Open (StrPath + StrName)
    ?

    Thanks.

    Cheers,
    Arie

  2. #2
    Junior Member
    Join Date
    Feb 2004
    Location
    Hull, England
    Posts
    19
    Hi Arie,

    All versions of M$ Windows can resolve the path ...

    Workbooks.Open (ActiveWorkbook.Path & "\..\" & StrName)

    or, to always return a legal path in unusual circumstances ...

    Workbooks.Open (ActiveWorkbook.Path & IIf(Right$(ActiveWorkbook.Path, 1) = "\", "", "\..\") & StrName)

Posting Permissions

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



Click Here to Expand Forum to Full Width