没有findVBA Application.FileDialog

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

我使用的是参考MS Office 14.0对象库,VBA,MS Excel 14.0对象库,OLE自动化和MS表单2.0对象库。

为什么方法FilDialog不存在我的Mac上的应用程序类,但它适用于我的Windows?

根据本文 ,Excel 2011中不存在Application.FileDialog 。 试试这个解决scheme ,它会创build一个函数。

解决scheme如下,并允许它在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