本文介绍了在 Word VBA 中调用 Application.GetOpenFilename 方法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也就是说,我在按钮处理程序中调用了以下代码段:

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"

提前致谢!

推荐答案

Word 中没有 Application.GetOpenFilename.

您需要改用 FileDialog.这是一个简单的例子:

You need to use FileDialog instead. Here's a quick example:

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

这篇关于在 Word VBA 中调用 Application.GetOpenFilename 方法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 06:03