找不到VBA Application.FileDialog

时间:2013-09-17 17:51:55

标签: excel vba

我在Mac上运行Excel 2011,我的一个应用程序(适用于Windows版本)在我的Mac上无法运行。它无法在Application.FileDialog中找到方法“FileDialog”。

我使用的是ms office 14.0对象库,vba,ms excel 14.0对象库,ole自动化和ms表单2.0对象库。

为什么我的mac上的应用程序类不存在FilDialog方法,但它可以在我的窗口上运行?

1 个答案:

答案 0 :(得分:3)

根据{{​​3}},Excel 2011中不存在

Application.FileDialog。请尝试使用this article,它会创建一个函数。

解决方案如下,并允许它在Macintosh上运行:

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