Excel在输出文件的末尾添加空行

我有一个小但真正烦人的问题。 我写了一个代码来分析一定数量的数据,并以单元格的格式绘制出结果。 最后将结果转换成文件格式。 这是我的出口文件:

Sub ExportToTextFile() Dim WholeLine As String Dim FNum As Integer Dim sav_dir As String Dim file_dir As String Dim fsobj, fsfolder Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer Dim CellValue As String sav_dir = file_path Set fsobj = CreateObject("Scripting.FileSystemObject") If Not fsobj.FolderExists(sav_dir) Then fsobj.CreateFolder sav_dir End If Sheets("Map_TXT").Select Rows("217:1320").Select Application.CutCopyMode = False Selection.Delete FNum = FreeFile() StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = 216 EndCol = .Cells(.Cells.count).Column End With Open file_dir For Append Access Write As #FNum For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = Chr(0) 'Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Value End If WholeLine = WholeLine & CellValue Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine)) Print #FNum, WholeLine Next RowNdx Close #FNum EndMacro: On Error End Sub 

所以不pipe我做什么,这个函数在输出文件的末尾添加一个空行。 这个空行是行号217,我必须摆脱这最后一行。 有人可以提供一个解决scheme,如何删除该文件中的最后一行? 先谢谢你

用于写入最后一行(当RowNdx = EndRow)时使用

 Print #FNum, WholeLine; '<<< note the semicolon