Consulting

Results 1 to 5 of 5

Thread: Solved: Variable Filename / No Drive Letter Chosen

  1. #1

    Solved: Variable Filename / No Drive Letter Chosen

    I've been playing around with a couple options I've seen in other places but I can't seem to get any of them to work right. I am trying in my Workbook_BeforeSave event to check the workbook name (WkBk v3.27) and if it's named the original file, name it "AMO-"& .Range.value.

    I get the filename to save if it's just saving on my computer, however, I need to save the file to a different directory on an external(mobile) harddrive. Unfortunately, since everyone computer is different, I can't use Drive letter E: as a constant in the filepath.

    How can I find the drive letter that the open file came from so I can save the open file as a different name under the same drive letter/different folder?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    left$(activeworkbook.path,2)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks for the quick response Friday XLD, and sorry it took so long to get back, but I backed up the wrong file on my thumbdrive before I left work.

    Anyway, I tried what you said and so far I've got this :
    [vba]Public Sub AutoSv()
    Dim OrgDir As String
    OrgDir = Left$(ActiveWorkbook.Path, 2) & "amo\student information\blank materials\"
    ActiveWorkbook.SaveAs Filename:=OrgDir & "AMO-" & _
    Worksheets("Class Information").Range("j1").Value & ".xls"
    End Sub
    [/vba]

    Unfortunately, I'm getting an "Excel can not read this directory" error.

    Sub is in a Module.
    When I run it, it returns the error because it's finding the wrong folder, or rather, not the folder I'm looking for.

    I'm running the file from my desktop and instead of saving the file to "C:\amo\student information\blank materials\" as filename "AMO-13-13.xls", it's trying to save it as "C:\documents and settings\username\my documents\amo\student information\blank materials\".

    What am I missin here?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    Public Sub AutoSv()
    Dim OrgDir As String
    OrgDir = Left$(ActiveWorkbook.Path, 2) & "\amo\student information\blank materials\"
    ActiveWorkbook.SaveAs Filename:=OrgDir & "AMO-" & _
    Worksheets("Class Information").Range("j1").Value & ".xls"
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    wow... something so small... thanks yet again.

Posting Permissions

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