Using msoFileDialogFolderPicker to select a folder

Anonymous
2014-09-18T12:08:33+00:00

Hello

The following code is written to allow the user to select the folder where they wish to save a PDF of the worksheet and the file name will consist of data located in cells D4 and D5.  It also checks to confirm that the data in cell D5 contains 3 characters.  The code works fine but with one issue.  If the user drills down say 4 levels of subfolders the file does not save in the folder, it saves in the folder one level up. 

I can't figure out why the file is not saved it the folder selected.

Can someone indicate what I am missing?

Thank you

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
Answer accepted by question author
  1. Anonymous
    2014-09-18T13:00:19+00:00

    Hi

    Have a try with this

    Dim strCurrDir As String

    Dim fldpath As String

    Debug.Print CurDir

    strCurrDir = CurDir 'keep track of current directory

    Application.FileDialog(msoFileDialogFolderPicker).Show

    Debug.Print CurDir

    fldpath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)

    ChDir fldpath 'chang to the new directory

    Debug.Print CurDir

    'Do your stuff

    ChDir strCurrDir 'reset to previous current directory

    End Sub

    HTH

    Regards

    JY

    2 people found this answer helpful.
    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-09-18T16:20:29+00:00

    Hi

    You are welcome. Glad to help.

    Regards

    JY

    0 comments No comments