Issue
I need to process some files in Excel that may be in Unix or Windows format. I already have the right code to read each one, but I need to know in advance the file type before calling the right procedure.
Is there an easy way to identify the file type (Unix / Windows) using VBA?
Thanks
Solution
You could use something like this to count:
Private Sub CountCRLF()
Dim TmpStr$()
TmpStr = Split(Text1.Text, Chr(13) & Chr(10))
MsgBox "There are " & UBound(TmpStr()) & " CRLF's in string", vbInformation, "Count"
End Sub
If that is more than a few, it should be a Windows file. If a file mixes both types of line breaks, a more complex approach would be needed.
But this worries me in terms of performance, unless you are sure the files are really small. And something in your question makes me think you already have a function to handle the lines one by one and you should probably try to only process these files once, detecting and handling as you go along...
Answered By - joser Answer Checked By - Terry (WPSolving Volunteer)