Share via

VBA Issue - Application.FileDialog return Nothing

Anonymous
2022-04-25T16:40:36+00:00

Is there something wrong with the lines of code below? It results in the following error.

thumbnail image 1 of blog post titled                                              VBA Issue - Application.FileDialog return Nothing

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
Microsoft 365 and Office | Excel | Other | MacOS

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

Answer accepted by question author

HansV 462.6K Reputation points
2022-04-25T17:14:48+00:00

I don't think FileDialog works on a Mac. See Loop through Files in Folder on Mac for an alternative.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-04-26T18:00:36+00:00

    Hi

    Please refer to this page by MVP Ron DeBruin for examples on how to work with files and folders:

    https://www.macexcel.com/examples/filesandfolders/

    Thanks Jim

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-04-26T18:00:02+00:00

    Thanks HansV.

    Was this answer helpful?

    0 comments No comments
  3. Jim G 134K Reputation points MVP Volunteer Moderator
    2022-04-26T17:50:39+00:00

    Hi

    Please refer to this page by MVP Ron DeBruin for examples on how to work with files and folders:

    https://www.macexcel.com/examples/filesandfolders/

    Was this answer helpful?

    0 comments No comments