Introduction: I have been using the same code (below) for FileDialog
with Late Binding for PC and also MAC for a long time.
My Problem: Some new MACs in my company which have newer Office version for MAC, Version 15.1 and above, get the following:
Run-time error 438: Object doesn't support this property or method
At the following line:
Set fDialog = Application.FileDialog(3)
Any ideas what modification needed to be made to make it work with Office Ver 15.1 for MAC?
My Code
Option Explicit
Function OpenXLSFileName(strPath As String, MediaName As String) As String
Dim xlsFileName As String
Dim fDialog As Object
Set fDialog = Application.FileDialog(3) ' <-- get the error here (msoFileDialogFilePicker = 3)
' FileDialog properties
With fDialog
.AllowMultiSelect = False
.Title = "Select data records file for media " & MediaName
.InitialFileName = strPath
' Add filters
.Filters.Clear
.Filters.Add "Excel files", "*.xls;*.xlsx;*.csv"
If .Show = -1 Then ' -1 means success
OpenXLSFileName = .SelectedItems(1)
Else
MsgBox "No Excel file selected !", vbExclamation, "Warning"
OpenXLSFileName = ""
End If
End With
Set fDialog = Nothing
End Function