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!
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
来源:https://stackoverflow.com/questions/10159216/whats-wrong-with-calling-application-getopenfilename-method-in-word-vba