I have a folder that contains 100 csv files. I need to delete the same columns from each of these files. I have tried several variations of the code below without success. I keep receiving a syntax error. I have tried everything I can find and keep striking out. Any help would be greatly appreciated!
Sub LoopAllFilesInFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
myPath = "C:\Desktop\Test"
myExtension = "*.csv*"
myFile = Dir(myPath & myExtension)
Do While MyFile <> ""
If Len(myFile) = 0 Then Exit Do
Set wb = Workbooks.Open(Filename:=myPath & myFile)
Columns("B:Y").EntireColumn.Delete
wb.Close SaveChanges:=True
End If
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Task Complete!"
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub LoopAllFilesInFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
myPath = "C:\Desktop\Test"
myExtension = "*.csv*"
myFile = Dir(myPath & myExtension)
Do While MyFile <> ""
If Len(myFile) = 0 Then Exit Do
Set wb = Workbooks.Open(Filename:=myPath & myFile)
Columns("B:Y").EntireColumn.Delete
wb.Close SaveChanges:=True
End If
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Task Complete!"
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub