在 Word VBA 中调用 Application.GetOpenFilename 方法有什么问题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10159216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's wrong with calling Application.GetOpenFilename method in Word VBA?
提问by stanigator
Namely, I called the following snippet in a button handler:
即,我在按钮处理程序中调用了以下代码段:
TextBox1.Text = Application.GetOpenFilename("All files (*.*),*.*", _
1, "Open the Raw Data Files", , False)
If TextBox1.Text = "False" Then TextBox1.Text = ""
The error said: "Compiler error: Method or data member not found"
错误说:“编译器错误:未找到方法或数据成员”
Thanks in advance!
提前致谢!
回答by Ken White
There is no Application.GetOpenFilenamein Word.
Application.GetOpenFilenameWord 中没有。
You need to use FileDialoginstead. Here's a quick example:
你需要FileDialog改用。这是一个快速示例:
Private Sub CommandButton1_Click()
Dim s As Variant
Dim Res As Integer
Dim dlgSaveAs As FileDialog
Set dlgSaveAs = Application.FileDialog( _
FileDialogType:=msoFileDialogSaveAs)
Res = dlgSaveAs.Show
If Not Res = 0 Then
For Each s In dlgSaveAs.SelectedItems 'There is only one
MsgBox s
Next
End If
End Sub

