Excel 找不到VBA Application.FileDialog
我在Mac电脑上运行Excel 2011,我的一个应用程序在windows版本上运行,但在Mac电脑上无法运行。在Application.FileDialog中找不到方法“FileDialog” 我使用的是参考ms office 14.0对象库、vba、ms excel 14.0对象库、ole automation和ms forms 2.0对象库Excel 找不到VBA Application.FileDialog,excel,vba,Excel,Vba,我在Mac电脑上运行Excel 2011,我的一个应用程序在windows版本上运行,但在Mac电脑上无法运行。在Application.FileDialog中找不到方法“FileDialog” 我使用的是参考ms office 14.0对象库、vba、ms excel 14.0对象库、ole automation和ms forms 2.0对象库 为什么我的mac上的application类不存在FilDialog方法,但它在我的windows上工作?应用程序。FileDialog在Excel
为什么我的mac上的application类不存在FilDialog方法,但它在我的windows上工作?
应用程序。FileDialog
在Excel 2011中不存在。相反,它会创建一个函数
解决方案如下,并允许it在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