Convert Linux files to Windows

bkelly

Active Member
Joined
Jan 28, 2005
Messages
465
I received a bunch of text files from a Linux system. They have LF but no CR. When reading the file Excel VBA reads the entire file as one line.
I write a little routine that makes the change. All the file names are in the array of strings.
&&&&&&&&&&
For file_number = 1 To FILE_NAME_COUNT
input_file_name = DIR_NAME + file_names(file_number)
Open input_file_name For Input As #2
Line Input #2 , text
read_length = Len(text)
text = Replace(text, Chr(10), vbCrLf)
Close #2
Open input_file_name For Output As #2
Print #2 , text
Close #2
Next file_number
&&&&&&&&&&

Problem: The Print line prints only up to the first CR. What can I use to write the entire string?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Bryan,
Try this:
Rich (BB code):
  Dim FF As Integer, s As String
  For file_number = 1 To FILE_NAME_COUNT
    input_file_name = DIR_NAME & file_names(file_number)
    FF = FreeFile
    Open input_file_name For Binary Access Read Write As FF
    s = String(LOF(FF), " ")
    Get FF, , s
    If InStr(s, vbCrLf) = 0 Then
      s = Replace(s, vbLf, vbCrLf)
      Put FF, 1, s
    End If
    Close FF
  Next
Regards,
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top