利用commanddialog控件选择多个文件进行数据导入,一次执行完毕再次点击打开文件,程序报“实施错误20477,文件名无效”,请高手指点。

解决方案 »

  1.   

    你是怎么导入的?估计你没有对文件名进行处理,看下面的代码:
    Private Sub mOpenFile(FileNames() As String, ByVal FilterString As String)
        Dim i As Long
        CommonDialog1.FileName = ""
        CommonDialog1.Filter = FilterString
        CommonDialog1.MaxFileSize = 32767
        CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
        CommonDialog1.ShowOpen
        Dim buff() As String
        buff = Split(Me.CommonDialog1.FileName, vbNullChar)
        If UBound(buff) = 0 Then
            ReDim FileNames(0)
            FileNames(0) = buff(0)
        Else
            ReDim FileNames(UBound(buff) - 1)
            For i = 1 To UBound(buff)
                FileNames(i - 1) = buff(0) + "\" + buff(i)
            Next
        End If
    End Sub