没有找到VBA Application.FileDialog [英] VBA Application.FileDialog not found

查看:240
本文介绍了没有找到VBA Application.FileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mac上运行Excel 2011,我的一个应用程序(在windows版本上运行)在我的Mac上不起作用。我在Application.FileDialog中找不到方法FileDialog。



我正在使用引用ms office 14.0对象库,vba,ms excel 14.0对象库,ole自动化, ms形成2.0对象库。



为什么我的Mac上的应用程序类的FilDialog方法不存在,但它在我的窗口上工作?

解决方案

Application.FileDialog 根据这篇文章。尝试此解决方案,它创建一个函数。



解决方案如下,并允许它在Macintosh上工作: p>

 函数myGetOpenFileName(可选的sPath As String)As String 
Dim sFile As String
Dim sMacScript As String

如果isMac Then
如果sPath = vbNullString然后
sPath =文件夹的路径
Else
sPath =alias& sPath&
End If
sMacScript =set sFile to(choose file of type({& _
com.microsoft.Excel.xls,
org.openxmlformats.spreadsheetml.sheet,
public.comma-isolated-values-text,public.text
public.csv ,
org.openxmlformats.spreadsheetml.sheet.macroenabled}),并提示& _
选择要导入的文件默认位置& sPath& )作为字符串_
& vbLf& _
return sFile
Debug.Print sMacScript
sFile = MacScript(sMacScript)

其他的$ Windows

sFile =应用程序。 GetOpenFilename(CSV文件,* .csv,Excel 2007文件,*。xlsx,1,_
选择要导入的文件,& Import,False)

结束如果


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?

解决方案

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

这篇关于没有找到VBA Application.FileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆