The code below, loops through files in a folder a processes them by calling the macro Torque_kin. Before that it checks to see if the value in cell c2 is greater than 0 and if its not it saves file with the date in cell a2 and closes.
My question is, how can I save it with it original file name? instead of renaming it with the date in cell a2.
Thanks
My question is, how can I save it with it original file name? instead of renaming it with the date in cell a2.
Thanks
Code:
Sub Macro1()
'//Change the path to the main folder, accordingly
Call RecursiveFolders("C:\Main folder")
End Sub
Sub RecursiveFolders(ByVal MyPath As String)
Dim FileSys As Object
Dim objFolder As Object
Dim objSubFolder As Object
Dim objFile As Object
Dim wkbOpen As Workbook
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = FileSys.GetFolder(MyPath)
Application.ScreenUpdating = False
For Each objSubFolder In objFolder.SubFolders
For Each objFile In objSubFolder.Files
Set wkbOpen = Workbooks.Open(FileName:=objFile)
'Check first speed value, should be = 0, if not save file to 'bad data' folder and close
Range("c2").Select
If ActiveCell.Value > 0 Then
Application.DisplayAlerts = False
ActiveSheet.Copy
ActiveWorkbook.SaveAs FileName:="C:\Bad data\" & Format(ActiveSheet.Range("A2"), "YYYYMMDDHHMMSS") & ".xls"
ActiveWorkbook.Close
Else
'Call macro here
Call torque_kin
End If
'Change to true if you want to save raw and kinematic sheets etc
wkbOpen.Close savechanges:=False
Next
Call RecursiveFolders(objSubFolder.Path)
Next
Application.ScreenUpdating = True
End Sub