stanigator
stanigator

Reputation: 10944

What's wrong with calling Application.GetOpenFilename method in Word VBA?

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!

Upvotes: 3

Views: 12271

Answers (1)

Ken White
Ken White

Reputation: 125749

There is no Application.GetOpenFilename in Word.

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

Upvotes: 9

Related Questions