Try this,
Sub CreateTextFile()
Sheets("ASCII01").Select
Dim intUnit As Integer
Dim FileName As String
Dim FilePath As String
Dim MyFile As String
Dim rngRow As Range
Dim rngCell As Range
Dim strBuf As String
FileName = "DHPT01.txt"
FilePath = "C:\Temp2\"
If Len(Dir("C:\temp2", vbDirectory)) = 0 Then
MkDir FilePath
End If
intUnit = FreeFile
MyFile = FilePath & "\" & FileName
Open MyFile For Output As #intUnit
For Each rngRow In ActiveSheet.UsedRange.Rows
If Application.WorksheetFunction.CountA(rngRow) > 0 Then
strBuf = ""
For Each rngCell In rngRow.Cells
If rngCell.NumberFormat <> "General" Then
strBuf = strBuf & Format(rngCell.Value2, rngCell.NumberFormat) & ","
Else
strBuf = strBuf & rngCell.Value & ","
End If
Next
Print #intUnit, Left(strBuf, Len(strBuf) - 1)
End If
Next
Close #intUnit
End Sub
I have changed FB to intUnit. The is a pointer to the File stream.
I have added code to use the number format. You may need to refine this for other data sets.
Bookmarks