Hi & welcome to MrExcel.
In addition to
@severynm's suggestions to eliminate the characters you might not be aware of, I would like to note that the output always differs from your input since you're using the
Print
statement.
Print
expects the output to be a single text line and always adds two bytes and the end of each output: Carriage Return (13 / &hex 0D) and LineFeed (10 / &hex 0A).
If you don't want that to happen, try using the
Put
statement and open your file for binary access. That way you have full control.
Note that's best to get the cell's content by using the Text property. That way you get the data exactly as it is on the screen, including currency characters or percent signs.
The use of a buffer is needed as well, otherwise there are so called
descriptors added and that way you will not get plain text files.
As a first side note, it's not necessary to select a cell to obtain its contents.
As a second side note, the worksheet ranges aren't qualified in your code (like
Worksheet("MySheet").Range("B5")
) which may lead to unexpected results.
Finally, to avoid repetitive code you might consider using a separate procedure to write data to a text file. This could look something like this:
VBA Code:
Sub Wingger()
' === usage example ====
Dim FileName As String, DataBuffer As String
FileName = "C:\Users\public\Desktop\Weber Labeler Files\Data Text Files\Sold To.txt"
DataBuffer = Range("B5").Text
WriteTextFile FileName, DataBuffer
End Sub
Public Sub WriteTextFile(ByVal argFullFileName As String, ByRef argText As String)
Dim FileHandle As Long
FileHandle = FreeFile
Open argFullFileName For Binary Access Read Write Lock Read Write As #FileHandle
Put #FileHandle, , argText
Close #FileHandle
End Sub