views:

39

answers:

1

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

Here is a sample text file generated from this code: link. You would probably have to download it and open it in notepad to see the blank row.

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

End Sub

+1  A: 

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

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.

Try the following instead:

Print #1, exportTxt;
barrowc
This worked, thank you so much!
Shawn H