I'm trying to take all txt files in a folder and convert them to excel files. I 'borrowed' the below code and it seems to work EXCEPT that it only does text to columns on the header line. (Be gentle - I so appreciate all your expertise, but I'm really not great at this... Any help is appreciated!)
Code:
Private Sub Command108_Click()
Dim sDir As String
Dim objXl As Object
Dim objWB As Object
Dim objSH As Object
Const xlDelimited As Integer = 1
Const xlDoubleQuote As Integer = 1
Const xlOpenXMLWorkbook As Integer = 51
sPath = "G:\CCCN\Payer Relations-Contracting\Payer Data Files\Anthem\test convert\"
Set objXl = CreateObject("Excel.Application")
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir$(sPath & "*.txt", vbNormal)
Do Until Len(sDir) = 0
Set objWB = objXl.Workbooks.Open(sPath & sDir)
Set objSH = objWB.sheets(1)
With objSH
objXl.Selection.TextToColumns Destination:=.Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="|", FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
End With
objWB.SaveAs FileName:=Left(objWB.FullName, InStrRev(objWB.FullName, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
objWB.Close False
Set objSH = Nothing
Set objWB = Nothing
sDir = Dir$
Loop
objXl.Quit
Set objXl = Nothing
End Sub