Results 1 to 3 of 3

Thread: [RESOLVED] Excel "Save as" with path?

  1. #1

    Thread Starter
    Lively Member adifel's Avatar
    Join Date
    Jan 2006
    Location
    California
    Posts
    103

    Resolved [RESOLVED] Excel "Save as" with path?

    I am using this sub to save the active workbook:

    Code:
    Private Sub FileSave()
      flFormat = ActiveWorkbook.FileFormat
      flName = Range("D5").Value & ".xls"
      flToSave = Application.GetSaveAsFilename(flName, filefilter:="Excel Files (*.xls), *.xls", _
        Title:="Save FileAs...")
      If flToSave = False Then
        Exit Sub
      Else
        ThisWorkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
      End If 'flToSave = False
    End Sub 'FileSave()
    but I can't figure out how to set the default directory to let's say "H:\Team A".

    As there are lots of team members using the same template, I cant set up the name with the path included (e.g. Application.ActiveWorkbook.SaveAs "H:\Team A\John\Item.xls").
    I found on the forums all kind of ideas, e.g. using ChDir, but none works.
    Any suggestions will be appreciated.
    Last edited by adifel; Oct 29th, 2008 at 01:03 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel "Save as" with path?

    if flname ends in \ then the dialog will open the specified directory with no default file name
    you can set the path as a variable and combine the path and file name, something like
    Code:
    mypath = "h:\team A\" & environ("username") &"\"
    flToSave = Application.GetSaveAsFilename(mypath & flName, filefilter:="Excel Files (*.xls), *.xls", _
        Title:="Save FileAs...")
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member adifel's Avatar
    Join Date
    Jan 2006
    Location
    California
    Posts
    103

    Re: Excel "Save as" with path?

    Works like a charm (I tried that before but for some reason it didn't work...). 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
  •  



Click Here to Expand Forum to Full Width