Hi,
I'm attempting to select a folder and have that folder file path write to the left of the active cell and for the folder name to write to the active cell.
However, it is not writing the Folder Name.
Please help me get this fixed.
Thanks
I'm attempting to select a folder and have that folder file path write to the left of the active cell and for the folder name to write to the active cell.
However, it is not writing the Folder Name.
Please help me get this fixed.
Thanks
VBA Code:
Sub WritePathAndName()
Dim FldrPicker As FileDialog
Dim myFolder As String
Dim myFile As String
'Have User Select Folder to Save to with Dialog Box
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub 'Check if user clicked cancel button
myFolder = .SelectedItems(1) & "\"
End With
'Get the selected file name
myFile = Dir(myFolder)
'Write the folder path in the cell to the left of the active cell
ActiveCell.Offset(0, -1) = myFolder
'Write the selected file name in the cell to the right of the active cell
ActiveCell.Offset(0, 0) = myFile
End Sub