文件对话框错误访问 VBA [英] File Dialog error access VBA

查看:58
本文介绍了文件对话框错误访问 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让文件对话框弹出,以便用户可以选择文件路径以在 VBA 中导出文件,但由于某种原因,它会在以下代码行中引发此错误.

I am trying to have the file dialog box pop up so the user can select a file path to export a file in VBA but for some reason it throws this error on the following line of code.

错误:对象_Application"的方法FileDialog"失败

Error: Method 'FileDialog' of object '_Application' failed

代码:longResult = Application.FileDialog(msoFileDialogFolderPicker).Show

所有代码:

If choice = 6 Then

Dim intResult As Long
Dim strPath As String
'the dialog is displayed to the user
longResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
    'dispaly message box
Call MsgBox(Application.FileDialog(msoFileDialogFolderPicker _
    ).SelectedItems(1), vbInformation, "Selected Folder")
End If

Else

End

End If

我真的不确定如何解决这个问题.我检查了我的语法和所有内容.

I am really unsure how to fix this issue. I checked my syntax and everything.

推荐答案

我知道这是一个有点老的问题,但由于它实际上没有答案,我今天需要一个,我我将补充我的发现,以防其他人也需要答案.

I know that this is a bit of an old question at this point, but since it doesn't actually have the answer, and I needed one today, I'm going to chime in with what I found just in case anyone else needs the answer too.

要解决此问题,您需要在 Visual Basic Editor >> Tools >> References...

To fix this you need to add a reference to "Microsoft Office [yourversion] Object Library" in Visual Basic Editor >> Tools >> References...

有问题的对话框应如下所示:

The dialog in question should look like this:

这篇关于文件对话框错误访问 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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