防止.txt文件文件将最后一行另存为空白 [英] Prevent a .txt file file saving the last line as blank

查看:46
本文介绍了防止.txt文件文件将最后一行另存为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的.当此文件保存到.txt文件时,我希望最后一行是文本的最后一行,而不是它下面的空白行.请帮忙!谢谢.

This is what I have. When this saves to .txt file I would like for the last line to be the last line of text not the open line below it. Please help! Thank you.

Sub ExportColB()
Dim myFileName As String, rng As Range, txt As String
myFileName = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
If myFileName = "" Then Exit Sub
With Range("d3", Range("d" & Rows.Count).End(xlUp))
    If .Count < 2 Then
        txt = .Value
    Else
        txt = Join(Evaluate("transpose(" & _
        .Address(external:=True) & ")"), vbCrLf)
    End If
End With
Open myFileName For Output As #1
    Print #1, txt
Close #1
End Sub

推荐答案

不是使用 Print#1,txt 编写文件,而是总是将CRLF添加到文件末尾,请尝试打印#1,txt; .不要忘记分号.

Instead of using Print #1, txt to write the file which will always add CRLF to the end of the file try Print #1, txt;. Do not fortget the semicolon.

这篇关于防止.txt文件文件将最后一行另存为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆