Forum Discussion
JosephAdedeji
Apr 25, 2022Copper Contributor
VBA Issue - Application.FileDialog return Nothing
Is there something wrong with the lines of code below? It results in the following error.
Sub CountFiles()
Dim xFolder As String
Dim xPath As String
Dim xCount As Long
Dim xFiDialog As FileDialog
Dim xFile As String
Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFiDialog.Show = -1 Then
xFolder = xFiDialog.SelectedItems(1)
End If
If xFolder = "" Then Exit Sub
xPath = xFolder & "\*.xlsx"
xFile = Dir(xPath)
Do While xFile <> ""
xCount = xCount + 1
xFile = Dir()
Loop
MsgBox xCount & " files found"
End Sub
I don't think FileDialog works on a Mac. See Loop through Files in Folder on Mac for an alternative.
3 Replies
I don't think FileDialog works on a Mac. See Loop through Files in Folder on Mac for an alternative.
- JosephAdedejiCopper ContributorThanks Hans!
You're welcome!