Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Loopfiles()
- Dim wb As Workbook
- Dim myPath As String
- Dim myfile As String
- Dim myExtension As String
- Dim FldrPicker As FileDialog
- 'Optimize Macro Speed
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- Application.Calculation = xlCalculationManual
- 'Retrieve Target Folder Path From User
- Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
- With FldrPicker
- .Title = "Select A Target Folder"
- .AllowMultiSelect = False
- If .Show <> -1 Then GoTo NextCode
- myPath = .SelectedItems(1) & "\"
- End With
- 'In Case of Cancel
- NextCode:
- myPath = myPath
- If myPath = "" Then GoTo ResetSettings
- 'Target File Extension (must include wildcard "*")
- myExtension = "*.xls"
- 'Target Path with Ending Extention
- myfile = Dir(myPath & myExtension)
- 'Loop through each Excel file in folder
- Do While myfile <> ""
- 'Set variable equal to opened workbook
- Set wb = Workbooks.Open(Filename:=myPath & myfile)
- 'this is like the only bit i've added
- With ActiveWorkbook
- .SaveAs myPath & "\" & wb.Name, FileFormat:=xlCSV
- 'ok i have now stopped adding stuff
- wb.Close SaveChanges:=True
- 'Get next file name
- 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
- 'i lied
- MsgBox "Jose starves dogs to death, deliberately"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement