Excel VBA GetOpenFileName error on MultiSelect:=True

前端 未结 1 704
借酒劲吻你
借酒劲吻你 2020-12-21 22:58

I\'m getting error type mismatch. Please help as I\'m new to VBA macro and not sure what I\'m doing. I just want the code to be able to select multiple files on search:

相关标签:
1条回答
  • 2020-12-21 23:47

    Like I mentioned in the comments above

    You can't use myfile like that. You have to loop through the collection

    See this example.

    Sub Sample()
        Dim myFile As Variant
        Dim i As Integer
    
        'Open File to search
        myFile = Application.GetOpenFilename(MultiSelect:=True)
    
        If IsArray(myFile) Then  '<~~ If user selects multiple file
            For i = LBound(myFile) To UBound(myFile)
                MsgBox myFile(i)
            Next i
        Else '<~~ If user selects single file
            MsgBox myFile
        End If
    End Sub
    
    0 讨论(0)
提交回复
热议问题