在Word VBA中调用Application.GetOpenFilename方法有什么问题?

sta*_*tor 2 vba word-vba

即,我在按钮处理程序中调用了以下代码段:

TextBox1.Text = Application.GetOpenFilename("All files (*.*),*.*", _
        1, "Open the Raw Data Files", , False)
If TextBox1.Text = "False" Then TextBox1.Text = ""
Run Code Online (Sandbox Code Playgroud)

该错误说:“编译器错误:未找到方法或数据成员”

提前致谢!

Ken*_*ite 5

Application.GetOpenFilenameWord中没有。

您需要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
Run Code Online (Sandbox Code Playgroud)