ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Flat File formating with Print# Statement (https://www.excelbanter.com/excel-programming/284438-flat-file-formating-print-statement.html)

Mike Field

Flat File formating with Print# Statement
 
Using Excel 2000 v9.0
I have a list of records needing to be exported to a text
file.

What I am looking for is to output all records terminated
by a CR and no LF.
Example:
AB016593AY22001816P3404RS CHR(13) AB022350AY22201022P9920
CHR(13) AB022189AY18401823502031RS CHR(13)
My list will allways be in a single column with no breaks.

The following code works, but includes Hex OD 0D 0A at the
end of each record, removing & Chr(13) from the Print
statement will still result in 0D 0A.

Sub ExportTrans()
Count = 0

Sheets("Transactions").Select

Range("A1").Select

FilePath = [AppPathName] & "FADSMant.TXT"

Close #1

On Error Resume Next

Open FilePath For Output As #1

While ActiveCell.Value < ""

Print #1, ActiveCell.Offset(Count, 0).Value & Chr
(13)

Count = Count + 1

If ActiveCell.Offset(Count, 0).Value = "" Then
GoTo DropOut

Wend

DropOut:
Print #1, [DayToClear] & Chr(13)

Close #1

Exit Sub

Thanks,
Mike Field



Michael Hopwood

Flat File formating with Print# Statement
 
You would need to open the file as a binary file to do that, have a look in
help for details.

--
Michael Hopwood


"Mike Field" wrote in message
...
Using Excel 2000 v9.0
I have a list of records needing to be exported to a text
file.

What I am looking for is to output all records terminated
by a CR and no LF.
Example:
AB016593AY22001816P3404RS CHR(13) AB022350AY22201022P9920
CHR(13) AB022189AY18401823502031RS CHR(13)
My list will allways be in a single column with no breaks.

The following code works, but includes Hex OD 0D 0A at the
end of each record, removing & Chr(13) from the Print
statement will still result in 0D 0A.

Sub ExportTrans()
Count = 0

Sheets("Transactions").Select

Range("A1").Select

FilePath = [AppPathName] & "FADSMant.TXT"

Close #1

On Error Resume Next

Open FilePath For Output As #1

While ActiveCell.Value < ""

Print #1, ActiveCell.Offset(Count, 0).Value & Chr
(13)

Count = Count + 1

If ActiveCell.Offset(Count, 0).Value = "" Then
GoTo DropOut

Wend

DropOut:
Print #1, [DayToClear] & Chr(13)

Close #1

Exit Sub

Thanks,
Mike Field






All times are GMT +1. The time now is 12:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com