简体   繁体   English

通过 VBA 打开 .csv 文件会导致丢失行

[英]Opening a .csv file via VBA leads to missing rows

I am using a macro to open a set of selected .csv files, apply the TextToColumns command and then save them as a .xlsx file for further manual processing.我正在使用宏打开一组选定的 .csv 文件,应用 TextToColumns 命令,然后将它们保存为 .xlsx 文件以供进一步手动处理。 One particular .csv file has around 2000 lines in it if I open it manually;如果我手动打开一个特定的 .csv 文件,其中大约有 2000 行; when the file is opened via the macro it only contains a total of 1064 lines.当通过宏打开文件时,它总共只包含 1064 行。 Does anyone know what causes this or how I can fix it?有谁知道是什么原因造成的,或者我该如何解决? Relevant code:相关代码:

Dim iFileSelect As FileDialog
Dim vrtSelectedItem As Variant
Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)

If iFileSelect.Show = -1 Then
    Application.DisplayAlerts = False
    For Each vrtSelectedItem In iFileSelect.SelectedItems
        Workbooks.Open vrtSelectedItem 'After this step the opened csv-file only contains 1064 out of 2000 lines
        'Here a macro is run to convert text to columns
        ActiveWorkbook.Close
        SetAttr vrtSelectedItem, vbNormal
        Kill vrtSelectedItem
    Next vrtSelectedItem
    Application.DisplayAlerts = True
End If

Set iFileSelect = Nothing

For some reason, setting the Local parameter to True fixed it, I still don't know how or why so if anyone has any insights I'd appreciate it.出于某种原因,将 Local 参数设置为 True 修复了它,我仍然不知道如何或为什么,如果有人有任何见解,我将不胜感激。 Fixed code:固定代码:

Workbooks.Open vrtSelectedItem, Local:=True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM