导出时Excel VBA在文本文件的末尾添加多余的空行 [英] Excel VBA puts extra blank line at end of text file when exporting

查看:64
本文介绍了导出时Excel VBA在文本文件的末尾添加多余的空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输出到文本文件的Excel VBA宏.文本文件的底部总是有一个空白行,我很难摆脱它.任何有用的建议将不胜感激!谢谢

I have an Excel VBA macro that outputs to a text file. There is always a blank row at the bottom of the text file and I am having trouble getting rid of it. Any useful suggestions would be greatly appreciated! Thanks

Sub testExport()

  Dim fPath As String, exportTxt As String
  fPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Sample_" & Format(Now(), "HHNNSS") & ".txt"

  exportTxt = "Project: Sample Output" & vbCrLf
  exportTxt = exportTxt & "Model Version: 1 "


  Open fPath For Append As #1    'write the new file
  Print #1, exportTxt
  Close #1

结束子

推荐答案

Print#语句的帮助以及输出数据后指定 charpos 的方法:

From the help on the Print # statement and ways to specify charpos after the data has been output:

charpos 指定下一个字符的插入点.用一个用分号定位插入在最后一点之后立即指向显示的字符.使用Tab(n)来将插入点定位到绝对列号.将Tab与没有参数来定位插入指向下一个开始打印区域.如果省略了charpos,则在下一个字符上打印下一个字符线.

charpos Specifies the insertion point for the next character. Use a semicolon to position the insertion point immediately after the last character displayed. Use Tab(n) to position the insertion point to an absolute column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone. If charpos is omitted, the next character is printed on the next line.

请尝试以下操作:

Print #1, exportTxt;

这篇关于导出时Excel VBA在文本文件的末尾添加多余的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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