polarisking
Member
I suspect it has something to do with LF vs. CRLF recognition by VBA, but I'm hoping someone can help me understand how to read this file (attached) record by record. Right now, EOF is reached after the first Line Input command and the contents of strline = to the entire file's contents. Excel and Notepad parse the records just fine; VBA's not cooperating.
Code:
Sub test()
Dim fd As FileDialog
Dim strOpenPath As String
Dim strSavePath As String
Dim intOpenResult As Integer
Dim strFinal As String
Dim strLine As String
Close #1
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Filters.Clear
.Filters.Add "All Files", "*.txt"
.AllowMultiSelect = False
End With
intOpenResult = fd.Show
If intOpenResult <> 0 Then
strOpenPath = fd.SelectedItems(1)
Open strOpenPath For Input As #1
strFinal = ""
While EOF(1) = False
Line Input #1, strLine
Wend
Close #1
strSavePath = Application.GetSaveAsFilename(FileFilter:="Text File" & _
"(*.txt),*.txt", Title:="Save Location")
If strSavePath <> "False" Then
Open strSavePath For Output As #1
Print #1, strFinal
Close #1
End If
End If
End Sub