如何防止在文本文件中创build空白行
我有一个关于在我的文本文件生成的空白行的问题。我该怎么防止这种情况发生?
原始文本文件没有创build空行的数据
00|MAABBJQQ|AJ_20161206_001||||||||||||||||||||||||||
每当我点击我的button(button是指向下面的macrossub test()
)5倍,其中包含增量function
00|MAABBJQQ|AJ_20161206_005|||||||||||||||||||||||||| *blank row 1 *blank row 2 *blank row 3 *blank row 4 *blank row 5
这里是我的增量function代码,为你们了解我要去的。
Sub test() Dim fn As String, txt As String, myVal, temp fn = Application.GetOpenFilename("TextFiles,*.txt") If fn = "False" Then Exit Sub txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll With CreateObject("VBScript.RegExp") .Global = True .Pattern = "_(\d+)(?=\|)" myVal = Format$(.Execute(txt)(0).submatches(0) + 1, "_000") txt = .Replace(txt, myVal) Open Replace(fn, ".txt", "_Increment.txt") For Output As #1 Print #1, txt MsgBox "This is batch No" & myVal Close #1 End With End Sub
添加一个分号;
在您的Print
声明的最后:
Print #1, txt;
Print #
声明的细节可以在这里find。 请注意charpos参数设置。 使用分号会抑制插入换行符( CRLF
)。