Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using msoFileDialogFolderPicker to select a folder Hello The following code is w

ID: 3562434 • Letter: U

Question

Using msoFileDialogFolderPicker to select a folder

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

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote