选择文件

Sub test()
    arr = pickfiles
    If arr(1) <> "None" Then
        For i = LBound(arr) To UBound(arr)
        
            Debug.Print arr(i)
        Next i
    End If
End Sub



Function pickfiles() As String()
    Dim arr() As String
    Dim i As Long
    With Application.FileDialog(msoFileDialogFilePicker)
        .InitialFileName = Application.ActiveWorkbook.Path
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "Excel工作簿", "*.xls*"
        .Title = "请选取Excel工作簿"
        If .Show = -1 Then
            ReDim arr(1 To .SelectedItems.Count)
            For i = 1 To .SelectedItems.Count
                arr(i) = .SelectedItems(i)
            Next
            
        Else
            MsgBox "您未选择任何文件!", vbInformation, "Tips"
            ReDim arr(1 To 1)
            arr(1) = "None"
            
        End If
    End With
    
    pickfiles = arr
End Function

  

posted @ 2017-11-27 20:24  wangway  阅读(406)  评论(0编辑  收藏  举报