+ Reply to Thread
Results 1 to 7 of 7

Save file using part of folder name

  1. #1
    Registered User
    Join Date
    04-22-2006
    Posts
    6

    Save file using part of folder name

    Hi,

    Is there a way to save to a folder when only part of the folder name is known?

    The path i want to save it into H:\2006\2006_SomeProjectName\transmittal.xls

    2006 is stored in a variable ProjectYear and will always be know.
    SomeProjectName will always be unknown.

    So with the exceptioin of SomeProjectName (which i have shown as question marks) the save path would look something like this.
    ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\ transmittal.xls"

    Thanks for any help!

  2. #2
    Tom Ogilvy
    Guest

    Re: Save file using part of folder name

    Well, you could perhaps try to discover what it is:

    s = "H:\" & ProjectYear & "\"

    MyPath = s & ProjectYear & "*" ' Set the path.
    MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
    Do While MyName <> "" ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
    ' Use bitwise comparison to make sure MyName is a directory.

    If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
    Msgbox s & MyName ' Display entry only if it
    End If ' it represents a directory.
    End If
    MyName = Dir ' Get next entry.
    Loop

    But to actually save, you would need the actual path which you should be
    able to get from the above code.

    --
    Regards,
    Tom Ogilvy



    "Object" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi,
    >
    > Is there a way to save to a folder when only part of the folder name is
    > known?
    >
    > The path i want to save it into
    > H:\2006\2006_SomeProjectName\transmittal.xls
    >
    > 2006 is stored in a variable ProjectYear and will always be know.
    > SomeProjectName will always be unknown.
    >
    > So with the exceptioin of SomeProjectName (which i have shown as
    > question marks) the save path would look something like this.
    > ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\
    > transmittal.xls"
    >
    > Thanks for any help!
    >
    >
    > --
    > Object
    > ------------------------------------------------------------------------
    > Object's Profile:

    http://www.excelforum.com/member.php...o&userid=33752
    > View this thread: http://www.excelforum.com/showthread...hreadid=537649
    >




  3. #3
    Tim Williams
    Guest

    Re: Save file using part of folder name

    Is there only ever one subdirectory under "H:\2006\" ?

    What if there were two: (eg) 2006_SomeProjectName and 2006_SomeOtherProject ?
    Could that ever happen ?

    Tim


    "Object" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > Is there a way to save to a folder when only part of the folder name is
    > known?
    >
    > The path i want to save it into
    > H:\2006\2006_SomeProjectName\transmittal.xls
    >
    > 2006 is stored in a variable ProjectYear and will always be know.
    > SomeProjectName will always be unknown.
    >
    > So with the exceptioin of SomeProjectName (which i have shown as
    > question marks) the save path would look something like this.
    > ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\
    > transmittal.xls"
    >
    > Thanks for any help!
    >
    >
    > --
    > Object
    > ------------------------------------------------------------------------
    > Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
    > View this thread: http://www.excelforum.com/showthread...hreadid=537649
    >




  4. #4
    Registered User
    Join Date
    04-22-2006
    Posts
    6
    Thanks Tom,

    However the script keeps stopping at

    If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then

    any ideas?



    Quote Originally Posted by Tom Ogilvy
    Well, you could perhaps try to discover what it is:

    s = "H:\" & ProjectYear & "\"

    MyPath = s & ProjectYear & "*" ' Set the path.
    MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
    Do While MyName <> "" ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
    ' Use bitwise comparison to make sure MyName is a directory.

    If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
    Msgbox s & MyName ' Display entry only if it
    End If ' it represents a directory.
    End If
    MyName = Dir ' Get next entry.
    Loop

    But to actually save, you would need the actual path which you should be
    able to get from the above code.

    --
    Regards,
    Tom Ogilvy
    Last edited by Object; 04-30-2006 at 10:29 PM.

  5. #5
    Registered User
    Join Date
    04-22-2006
    Posts
    6
    Yes, there are several subdirectories under "H:\2006\". However there would never be 2 of the same name. The subdirectory could potentially not exist aswell, in which case i would like the script to stop.

    Quote Originally Posted by Tim Williams
    Is there only ever one subdirectory under "H:\2006\" ?

    What if there were two: (eg) 2006_SomeProjectName and 2006_SomeOtherProject ?
    Could that ever happen ?

    Tim
    Last edited by Object; 04-30-2006 at 10:33 PM.

  6. #6
    Tom Ogilvy
    Guest

    Re: Save file using part of folder name

    Yes, I didn't completely revise the code (it is some of the sample code from
    the DIR command)

    the offending line should actually be


    If (GetAttr(s & MyName) And vbDirectory) = vbDirectory Then

    --
    Regards,
    Tom Ogilvy


    "Object" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thanks Tom,
    >
    > However the script keeps stopping at
    >
    > If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
    >
    > any ideas?
    >
    >
    >
    > Tom Ogilvy Wrote:
    > > Well, you could perhaps try to discover what it is:
    > >
    > > s = "H:\" & ProjectYear & "\"
    > >
    > > MyPath = s & ProjectYear & "*" ' Set the path.
    > > MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
    > > Do While MyName <> "" ' Start the loop.
    > > ' Ignore the current directory and the encompassing directory.
    > > If MyName <> "." And MyName <> ".." Then
    > > ' Use bitwise comparison to make sure MyName is a directory.
    > >
    > > If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
    > > Msgbox s & MyName ' Display entry only if it
    > > End If ' it represents a directory.
    > > End If
    > > MyName = Dir ' Get next entry.
    > > Loop
    > >
    > > But to actually save, you would need the actual path which you should
    > > be
    > > able to get from the above code.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >

    >
    >
    > --
    > Object
    > ------------------------------------------------------------------------
    > Object's Profile:

    http://www.excelforum.com/member.php...o&userid=33752
    > View this thread: http://www.excelforum.com/showthread...hreadid=537649
    >




  7. #7
    Registered User
    Join Date
    04-22-2006
    Posts
    6
    Thanks alot Tom, all working perfectly.

    Quote Originally Posted by Tom Ogilvy
    Yes, I didn't completely revise the code (it is some of the sample code from
    the DIR command)

    the offending line should actually be


    If (GetAttr(s & MyName) And vbDirectory) = vbDirectory Then

    --
    Regards,
    Tom Ogilvy

    Cheers,

    Mark

+ 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