Hi - Need to ask for some help. I have a CSV file that is full of carriage returns and can open the file in Excel and use find and replace using alt 010 and this works. However I would like to use VBScript to manipulate the file in one action.
What I've got right now is not working and it errors out when looking for the array values.
Below is my code if anyone can provide assistance that would be great.
What I've got right now is not working and it errors out when looking for the array values.
Below is my code if anyone can provide assistance that would be great.
Code:
Const ForReading = 1
Dim Excel
Set objExcel = CreateObject("Excel.Application")
'Set objExcelQuit = getobject("Excel.Application")
objExcel.Visible = True
'Declares Date function
strToday = DateValue(Date)
'Opens New Workbook
Set objExcel2 = objExcel.Workbooks.Open("C:\Users\james\Desktop\TEMPLATE.xlsx")
str = replace( str, chr(10) , "")
'start pasting data in row 2
i = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
'input file from Emails
Set objFile = objFSO.OpenTextFile("C:\Users\james\Desktop\Extract1.CSV", ForReading) ' need to update
Set objWorksheet = objExcel.worksheets(1)
'Set objExcel = "C:\Users\james\Desktop\TEMPLATE.xlsx"
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
'Find and replace "Alt 010"
strLine = replace( strLine, chr(10) , ";")
'Find and replace ":"
strLine = replace ( strLine, ":" , ";")
arrLine = Split(strLine, ";")
strLoanNumber = FormatNumber (arrLine(1),0,IncLeadingZero)
strGoodThru = FormatDateTime(arrLine(13), vbGeneralDate)
'Writes to Excel Workbook
objWorksheet.Cells(i, 1).Value = strLoanNumber
objWorksheet.Cells(i, 2).Value = arrLine(5)
objWorksheet.Cells(i, 3).Value = strToday
objWorksheet.Cells(i, 4).Value = strGoodThru
objWorksheet.Cells(i, 5).Value = arrLine(17)
objWorksheet.Cells(i, 6).Value = arrLine(24)
objWorksheet.Cells(i, 7).Value = arrLine(10)
'End of Data needed
'during loop advances row by one
i = i + 1
Loop
set ObjRange = objWorksheet.UsedRange
set ObjRange1 = objWorksheet.Columns("C:D")
set ObjRange2 = objWorksheet.Columns("A:A")
objRange.EntireColumn.Autofit()
'objRange1.NumberFormat = "mm/dd/yyyy"
objRange2.NumberFormat = "0"
objWorksheet.SaveAs "C:\Users\james\Desktop\James123-FIRST.xlsx" ' need to update
objExcel2.close
objExcel.Quit