Excel Macro that allows user to browse to select a folder

Anonymous
2010-10-04T19:09:25+00:00

Hi

I currently have a macro that includes code to ask the user what filename they want to assign and then after the user enters a filename, it saves that filename in a specific place on the company network. (such as X:\Projects)

=======

file = InputBox("what do you want to call your file")

    ActiveWorkbook.SaveAs Filename:="X:\Projects" & file, FileFormat:= _

        xlCSV, CreateBackup:=False

======

Question: What code can I use to allow the user during the macro run to browse the company network and select a specific folder so the file, after they give it a name, is then saved in whatever folder they select (and not always to X:\Projects)??

Thanks very much

Craig

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2010-10-04T19:15:55+00:00

    You can use this...

    Application.GetSaveAsFilename

    to get the filename which you can then use in your save routine. Look GetSaveAsFilename up in the help files as there are optional arguments you might want to set.


    NOTE: Please mark the message or messages (yes, you can mark more than one) that answer your question as the "Answer" so that others will know your question has been resolved.

    0 comments No comments
  2. Anonymous
    2010-10-04T21:21:45+00:00

    Thank you!! I will try that...most helpful...thanks.

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 322.1K Reputation points MVP Volunteer Moderator
    2010-10-04T22:44:56+00:00

    Use

    Sub GetFolder()

    Dim strFolder as String

    Set fd = Application.FileDialog(msoFileDialogFolderPicker)

    With fd

        .Title = "Select the folder into which the documents will be saved."

        If .Show = -1 Then

            strFolder = .SelectedItems(1) & ""

        Else

            MsgBox "The documents will be saved in the default document file location."

            strFolder = ""

        End If

    End With

    End Sub

    -- Hope this helps.

    Doug Robbins - Word MVP,

    dkr[atsymbol]mvps[dot]org

    Posted via the Community Bridge

    "CraigBr1" wrote in message news:*** Email address is removed for privacy ***...

    Hi

    I currently have a macro that includes code to ask the user what filename they want to assign and then after the user enters a filename, it saves that filename in a specific place on the company network. (such as X:\Projects)

    =======

        file = InputBox("what do you want to call your file")

        ActiveWorkbook.SaveAs Filename:="X:\Projects" & file, FileFormat:= _

            xlCSV, CreateBackup:=False

    ======

    Question: What code can I use to allow the user during the macro run to browse the company network and select a specific folder so the file, after they give it a name, is then saved in whatever folder they select (and not always to X:\Projects)??

    Thanks very much

    Craig


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2013-07-01T11:11:14+00:00

    Thanks Doug

    0 comments No comments