我正在尝试将 Excel 范围复制到 .txt 文件。
导出成功,除了一个例外,它在末尾添加了一个“额外”的空行。
我已经阅读并测试了SO(和其他站点)上的许多解决方案,但仍然没有任何成功。
我的代码(相关部分)
' === Export to the .txt file ===
Dim TxtFileName As String, lineText As String
TxtFileName = ThisWorkbook.Path & "\Inv_" & Format(Date, "yyyymmdd") & ".txt"
Open TxtFileName For Output As #1
With StockSht
    For i = 1 To LastRow
        For j = 1 To 3
            If j = 3 Then
                lineText = lineText & .Cells(i, j).Value2
            Else ' j = 1 or 2
                lineText = lineText & .Cells(i, j).Value2 & vbTab
            End If
        Next j
        Print #1, lineText
        lineText = ""
    Next i
End With
Close #1
我的StockSht(工作表对象)并被LastRow正确定义,并获取它们的值。
导出的 .txt 文件结尾的屏幕截图
