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

ms-word, vba

Solution

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

Problem

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!

Original source