Hello,
I am having the following problems while executing the code. I kindly request support for rectifying the same.
1. Error Handling : If the specified input file doesn't exist then the VBA code is generating error.
2. I want to speed up this VBA using application.screenupdating = False. But i don't know where exactly i should use it in the code.
3. I want to close the Opened .Csv files before running into the next loop.
I have almost 5000 files to be processed .
I am having the following problems while executing the code. I kindly request support for rectifying the same.
1. Error Handling : If the specified input file doesn't exist then the VBA code is generating error.
2. I want to speed up this VBA using application.screenupdating = False. But i don't know where exactly i should use it in the code.
3. I want to close the Opened .Csv files before running into the next loop.
I have almost 5000 files to be processed .
Code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+a
'
Dim strPath As String, otrPath As String, startPath As String, Endpath As String, i As Long, buffer As String, startDate As Date
startPath = "E:\BSE\CM\" 'current directory
Endpath = "E:\BSE\OP\" 'output path
startDate = "14/06/2010" 'DD/MM/YYYY
Do While buffer <> "2011-06-04"
buffer = Format$(startDate, "YYYY-MM-DD")
strPath = startPath & buffer & "_BSECM.csv" 'full path of the file you want to open
otrPath = Endpath & buffer & ".txt"
startDate = startDate + 1 'add one day
'Your code
Workbooks.Open Filename:=(strPath)
Columns("I:I").Delete Shift:=xlToLeft
Rows("1:1").Delete Shift:=xlUp
Columns("B:B").Insert Shift:=xlToRight
Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="-", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Columns("B:B").Delete Shift:=xlToLeft
Columns("C:F").NumberFormat = "0.00"
Columns("B:B").NumberFormat = "yyyymmdd"
ActiveWorkbook.SaveAs Filename:=(otrPath), CreateBackup:=False
Loop
End Sub
Thank you