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

时间:2012-04-15 03:09:48

标签: vba word-vba

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

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

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

提前致谢!

1 个答案:

答案 0 :(得分:4)

Word中没有Application.GetOpenFilename

您需要使用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