Excel将宏转换为多个文件

问题描述

我制作了这个 Excel VBA 函数。此函数读取一个 csv 文件(只有 2 条记录:标题和信息)并将信息记录复制到工作表中。该功能由“导入文件”按钮激活,每次它都会在第一个可用的空记录上写入新记录。

Sub ImportFileButton_Click()
    Dim my_file As Integer
    Dim j As Long
    Dim letter As String
    Dim text_line As String
    Dim file_name As String
    Dim i As Integer
    Dim name_array() As String
    Dim unusedRow As Long

    file_name = Application.GetopenFilename()
    my_file = 3
    unusedRow = Sheets(1).Cells(Rows.Count,"A").End(xlUp).Row + 1
    
    Open file_name For Input As my_file
    i = 1
    While Not EOF(my_file)
        Line Input #my_file,text_line
        If i = 2 Then
            name_array = Split(text_line,";")
            
            Cells(unusedRow,"A").Value = Date
            Cells(unusedRow,"B").Value = Dir(file_name)
            For j = LBound(name_array) To UBound(name_array)
                letter = ConvertToLetter(j + 3)
                Cells(unusedRow,letter).Value = name_array(j)
            Next j
        End If
        i = i + 1
    Wend
    Close
End Sub

它可以工作,但它的功能不是多选。这意味着我每次使用按钮时可以导入 1 个文件,这很不舒服。

我希望我的函数通过单击导入更多文件并成为多选。我试过这个:

file_name = Application.GetopenFilename(Multiselect:=true)

但是我不知道如何管理这个“文件数组”。有人可以给我一个提示吗?

我尝试使用 For Each 进行迭代,但它不起作用,因为文件不是数组或矩阵:

file_name = Application.GetopenFilename(MultiSelect:=True)
For Each File In file_name
////
Next

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)