A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
I don't think FileDialog works on a Mac. See Loop through Files in Folder on Mac for an alternative.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
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.
Answer accepted by question author
I don't think FileDialog works on a Mac. See Loop through Files in Folder on Mac for an alternative.
Hi
Please refer to this page by MVP Ron DeBruin for examples on how to work with files and folders:
Thanks Jim
Thanks HansV.
Hi
Please refer to this page by MVP Ron DeBruin for examples on how to work with files and folders: