循环关闭csv文件

时间:2018-07-19 09:26:06

标签: excel vba csv

我想从同一文件夹中打开许多csv文件,将数据复制到'collectdatahere.xlsm',然后关闭csv文件并打开下一个文件。

即使我以相同的方式打开文件,我仍然收到错误消息Subscript out of range

Sub osszefuz()
    Dim Folder As String
    Dim File As String
    Dim wbname As String

    Sheets("Munka1").Range("A2").Select
    Folder = "Z:\project\path"
    File = Dir(Folder & "\*.csv")

    Do While File <> ""
        Workbooks.Open Filename:=Folder & "\" & File, Local:=True
        wbname = Folder & "\" & File
        Range("A2", Range("E2").End(xlDown)).SpecialCells(xlCellTypeVisible).Copy
        Workbooks("collectdatahere.xlsm").Activate
        Selection.PasteSpecial Paste:=xlValues
        Range("A1").End(xlDown).Offset(1, 0).Select
        **Workbooks(wbname).Close savechanges:=False**
        File = Dir
    Loop
End Sub

1 个答案:

答案 0 :(得分:0)

您不需要type=text/javascript;试试下面的代码,看看它是否满足您的要求:

SELECT