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

前端 未结 1 1685
醉话见心
醉话见心 2021-01-22 07:32

Namely, I called the following snippet in a button handler:

TextBox1.Text = Application.GetOpenFilename(\"All files (*.*),*.*\", _
        1, \"Open the Raw Data         


        
相关标签:
1条回答
  • 2021-01-22 08:04

    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
    
    0 讨论(0)
提交回复
热议问题