TheRedCardinal
Board Regular
- Joined
- Jul 11, 2019
- Messages
- 243
- Office Version
- 365
- 2021
- Platform
- Windows
I am asking the user to select a folder. I then want to post the string to a table in Excel.
I am using a Function I found on here, and on OzGrid:
Then in my code:
My message box contains the fixed text but nothing for the StrPath variable.
I've done something obvious wrong....?
I am using a Function I found on here, and on OzGrid:
VBA Code:
Function GetFolder(StrPath)
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = StrPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
Then in my code:
VBA Code:
If Answer = vbYes Then
GetFolder (StrPath)
MsgBox ("The selected folder was " & StrPath)
End If
My message box contains the fixed text but nothing for the StrPath variable.
I've done something obvious wrong....?