+ Reply to Thread
Results 1 to 6 of 6

Save As Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2011
    Location
    Belfast
    MS-Off Ver
    Excel 2007
    Posts
    34

    Save As Problem

    Hi, I have a macro that brings up a dialog box asking the user what they would like to name the file:
    Dim MyInput
    MyInput = InputBox("What would you like to name the file? i.e. BT Report 10_12_11")
    Dim FN As String
    FN = MyInput
    ActiveWorkbook.SaveAs Filename:=FN & ".xls"
    I have previously directed things to a specific folder like this:
    Dim FP As String, FN As String
        FP = "W:\Planning\"
        FN = MyInput
        ActiveWorkbook.SaveAs Filename:=FP & FN & ".xls"
    What I want to do now is have a second input box for the user to select the folder at the end of a specific path. What I tried was:
    Dim MyInput
    MyInput = InputBox("What would you like to name the file? i.e. BT Report 10_12_11")
    Dim MyInput2
    MyInput2 = InputBox("Which folder would you like to save to?")
    Dim FP As String, FN As String
    FP = "W:\Planning\" & MyInput2
    FN = MyInput
    ActiveWorkbook.SaveAs Filename:=FP & FN & ".xls"
    I have it wrong somewhere but I can't figure out where. Can anyone suggest a way of doing this? (the folders will always be in W:\Planning)

    Thanks,

    Dean
    Last edited by Dean81; 12-21-2011 at 06:33 AM.

  2. #2
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Save As Problem

    you could do something like this
    Dim FileSaveDLG As FileDialog
    Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs)
    With FileSaveDLG
        If .Show = -1 Then
            ActiveWorkbook.SaveAs .SelectedItems(1)
        End If
    End With

  3. #3
    Registered User
    Join Date
    09-20-2011
    Location
    Belfast
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Save As Problem

    That's the kitty! the only thing is it brings up My Documents as the default location, how can I make it open at say "W:\Planning", I tried adding ChDir at the start and after the "Then" but no joy. Any ideas?

    Thanks for your response by the way. I don't know where I'd be without this forum!

  4. #4
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Save As Problem

    add the line in bold
    Dim FileSaveDLG As FileDialog
    Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs)
    With FileSaveDLG
        .InitialFileName = "W:\Planning"
        If .Show = -1 Then
            ActiveWorkbook.SaveAs .SelectedItems(1)
        End If
    End With

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save As Problem

    Dean,

    First, be sure to go back to your post #1 above and add CODE tags around your posted code, as per forum rules. We don't want your thread to get moderated, ok? Like mohd showed in their post above, and demonstrated in my signature below.

    Once you have a "method" that seems to be getting you close, try a forum/Google search on the main keywords to see what other "parameters" might be available, or to just view other examples of the method. IN this case, the keyword search would be for FileDialog(msoFileDialogSaveAs)...

    This is one of the additional parameters you can add:
    Dim FileSaveDLG As FileDialog
    Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs)
    With FileSaveDLG
        .InitialFileName = "W:\Planning\"
        If .Show = -1 Then
            ActiveWorkbook.SaveAs .SelectedItems(1)
        End If
    End With

    You could even go further and have it fill in a suggested filename:
              .InitialFileName = "W:\Planning\" & "MyFile-" & Format(Date, "mm-dd-yy")
    Last edited by JBeaucaire; 12-21-2011 at 05:46 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    09-20-2011
    Location
    Belfast
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Save As Problem

    Awesome! Thanks guys. That's exactly what I was after. Apologies for the lack of Code Tags.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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