2
votes

I am running Excel 2011 on a Mac and one of my applications, which works on windows versions, does not work on my Mac. It cannot find the method "FileDialog" in Application.FileDialog.

I am using the references ms office 14.0 object library, vba, ms excel 14.0 object library, ole automation, and ms forms 2.0 object library.

Why does the method FilDialog not exist for the application class on my mac, but it works on my windows?

1

1 Answers

3
votes

Application.FileDialog does not exist in Excel 2011 as per this article. Try this solution instead, it creates a function.

The solution is as follows, and allows the it to work on Macintosh as well:

Function myGetOpenFileName(Optional sPath As String) As String
Dim sFile As String
Dim sMacScript As String

If isMac Then
    If sPath = vbNullString Then
        sPath = "the path to documents folder"
    Else
        sPath = " alias """ & sPath & """"
    End If
    sMacScript = "set sFile to (choose file of type ({" & _
        """com.microsoft.Excel.xls"", 
        ""org.openxmlformats.spreadsheetml.sheet"",
        ""public.comma-separated-values-text"", ""public.text"", 
        ""public.csv"",
        ""org.openxmlformats.spreadsheetml.sheet.macroenabled""}) with prompt " & _
        """Select a file to import"" default location " & sPath & ") as string" _
        & vbLf & _
        "return sFile"
     Debug.Print sMacScript
    sFile = MacScript(sMacScript)

Else 'windows

    sFile = Application.GetOpenFilename("CSV files,*.csv,Excel 2007 files,*.xlsx", 1, _
        "Select file to import from", "&Import", False)

End If