Ладно, потратив некоторое время на его изучение и много времени на отладку, я наконец-то понял это и решил опубликовать свои результаты на случай, если кому-нибудь еще понадобится помощь с этим
Function PipeToTab(ByVal OriginalText As String) As String
'Runs though current line of text stored in original text'
On Error GoTo error1
Dim ThisString As String, NewString As String, a As Integer
NewString = ""
For a = 1 To Len(OriginalText)
'checks to see if current char is white space and if it is removes it
If Mid(OriginalText, a, 1) = " " Then
'checks to see if current char is | and if it is changes it to char$(9) (tab)
ElseIf Mid(OriginalText, a, 1) = "|" Then
NewString = NewString & Chr$(9)
Else
NewString = NewString & Mid(OriginalText, a, 1)
End If
Next
PipeToTab = NewString
Exit Function
error1:
MsgBox (Err.Description)
End Function`
Это функция, которую я придумал, чтобы преобразовать строку текста из текстового файла из "|" на вкладки, а также удаление любых дополнительных пробелов.
`Private Sub Convert_File_Click()
On Error GoTo error1
Dim pipe_file As Variant
Dim ThisString As String
Dim a As Integer
Dim rfs, rts, InputFile, wfs, wts, OutputFile As Object
Dim InputFileName, OutputFileName, OriginalText, updatedText As String
' File initialization
'open the original source file and create the output file with the name desired from textbox.
InputFileName = Me.FilePath 'filepath is a textbox that holds the location
'and name of where you want the textfile to go
Set rfs = CreateObject("Scripting.FileSystemObject")
Set InputFile = rfs.GetFile(InputFileName)
'open the text streams
Set rts = InputFile.OpenAsTextStream(1, -2) 'Read
Set wts = OutputFile.OpenAsTextStream(8, -2) 'Append
'then put line into conversion function and get the updated text
'move onto the next line until EOF
While rts.AtEndofStream = False
OriginalText = rts.ReadLine 'read current line of file
If OriginalText <> Empty Then
updatedText = PipeToTab(OriginalText)
wts.WriteLine updatedText 'put updated text into newly created file(output file)
Else
End If
Wend`
'Output file clean up
wts.Close
'Input File clean up
rts.Close
End If
'clear out filestreams
Set OutputFile = Nothing
Set wfs = Nothing
Set wts = Nothing
Set InputFile = Nothing
Set rfs = Nothing
Set rts = Nothing
Exit Sub
error1:
' File Clean up
rts.Close
Set InputFile = Nothing
Set rfs = Nothing
Set rts = Nothing
'Output
wts.Close
Set OutputFile = Nothing
Set wfs = Nothing
Set wts = Nothing
MsgBox (Err.Description)
End Sub
Эта кнопка используется для преобразования текстового файла. Я использовал текстовые потоки и средство чтения строк, чтобы отправлять каждую строку текстового файла в функцию конвейера.