With Visual Basic, I am confused by the fact that the behavior of the Print statement is that sometimes the following statement: will return an extra carriage "^ M" at the end of the line, but sometimes it is not. I wonder why?
filePath = "d:\tmp\FAE-IMM-Report-2012-Week.org" If Dir(filePath) <> "" Then Kill filePath End If outFile = FreeFile() Open filePath For Output As outFile Print
will create
while I wish without ^ M:
In one test program, almost the same code will not produce β^ Mβ.
Please, help! Many thanks.
After further experiment, I found that the following sentence using vbNewline and ";" at the end of print content, still does not solve my problem.
After careful isolation, I found that the cause of the problem is a character that seems to be a space, not just a space, followed by a new line and a carriage return. Before printing the text containing the offending line, carriage return is not possible, but as soon as the violation line is printed, each line, including the previous line, will have a carriage return.
I am not sure which particular offensive line is, since my VBA skill is still not too good.
Here is a copy of the offensive text from a spreadsheet cell:
"There is something invisible after this visible text After the invisible text, then there might be a carriage return $Chr(13) and/or newline"
I'm not sure if pastes will save content in a web browser. When pasting into emacs, I did not see a carriage return, while emacs should display it if there is one. Therefore, I assume that there is no carriage return in the violating line.
The following is a program that demonstrates the problem:
Sub DemoCarriageReturnWillAppear() Dim filePath As String Dim outFile Dim offendingText filePath = "d:\tmp\demoCarriageReturn.org" If Dir(filePath) <> "" Then Kill filePath End If outFile = FreeFile() Open filePath For Output As outFile Print
Here is the final result of the procedure described above:
#+AUTHOR: Yu Shen^M There is something invisible after this visible text After the invisible text, then there might be a carriage return $Chr(13) or newline^M
Please note that the above β^ Mβ is added by me, as carriage returns will not be displayed in the browser.
If you're interested, I can send you an excel file with offensive content.
I need your help on how to avoid this breaking line, or carriage return. (Iβm even trying to make a line Replace carriage return or a new line, because I found that as soon as I manually delete all the changes caused by another line, the problem will disappear. But the Replace call to replace vbNewline, Chr $ (13) or vbCrLf has no values.
Thanks for your further help!
YU