查询pipe道分隔文件不返回所有logging

我用ADODB查询使用VBA的pipe道分隔文本文件。 我曾尝试使用ACE和JET引擎,但结果是相同的,并不正确。 我在目录中保存了一个“schema.ini”文件,告诉引擎该文件是pipe道分隔的。 当查询完成时,我有数据,移动列和其他字段是空白,当我可以看到文本文件中的数据。 我使用CopyFromRecordset方法将结果传输到我的工作簿。 任何人都可以看到我的代码中的东西? 还是有人遇到这个?

我的连接string:

 With Conn .Provider = "Microsoft.ACE.OLEDB.12.0" .ConnectionString = "Data Source=" & strPath & ";" & _ "Extended Properties=""text;HDR=YES;FMT=Delimited""" .Open End With 

“strPath”的值:

 strPath = "H:\Folder\" 

SQLstring:

 strSQL = "SELECT * FROM " & strFile & ";" 

数据传输:

 With ThisWorkbook With .Sheets("CashFlows") .Range("a2").CopyFromRecordset Rst With .Range("a1") For i = 0 To Rst.Fields.Count - 1 .Offset(0, i) = Rst.Fields(i).Name Next i End With End With End With 

我从来没有与ADO(无论是王牌或喷气)的问题,我经常使用它们。 然而,我还没有用它们作为pipe道分隔的文件。

如果我的解释不清楚,或者需要更多的代码,请留下评论。

编辑请参阅下面的pipe道删除文本文件中的两行。 第一行正常parsing。 第二滴“651111100”和“654444475”。 最奇怪的是这些parsing完全正确,当我直接在Excel中打开它们,并使用文本到列。

 08/31/2015|000|000|Recital #5546|0000000012|88885463|123334563 08/31/2015|000|000|DII #7412|651111100|654444475|00000326541 

我重新检查了一下,问题只在于它正在丢弃列,而不是它正在移动它们。 对不起,有任何困惑。

UPDATE

我在文本文件中find/replace,并放入“^”而不是“|”。 然后我试图再次运行,我遇到了同样的问题!

虽然我仍然不确定问题的可能性,但以下是可用的解决scheme:

 Option Explicit Public Sub ImportTextFile() Dim lngRowNumber As Long Dim strImportFile As String Dim intNextFreeFile As Integer Dim strOneImportLine As String Dim arySplitLine As Variant With Application .ScreenUpdating = False .Calculation = xlManual .EnableEvents = False End With intNextFreeFile = FreeFile strImportFile = "C:\path\to\the\TextFile.csv" lngRowNumber = 1 Open strImportFile For Input Access Read As #intNextFreeFile Do While Not EOF(intNextFreeFile) Line Input #intNextFreeFile, strOneImportLine arySplitLine = Split(strOneImportLine, "|") Sheets(1).Cells(lngRowNumber, 1).Value2 = arySplitLine lngRowNumber = lngRowNumber + 1 Loop Close #intNextFreeFile With Application .ScreenUpdating = True .Calculation = xlAutomatic .EnableEvents = True End With End Sub 

在我的计算机上进行的testing在12秒内完成了80MB文件中一百万行的导入。 虽然我确信有更好的方法可以做到这一点胜过这个解决scheme,但在此期间您可能会尝试一下。