So I am trying to loop through all the files in a folder and make either changes to the extension, the name or both. I have code (see below) and the problem is that it is only looping through files with extension ".xslx". I need to make changes to the names of all ".pdf". I need to make changes to the names of all ".xlsx". And finally, I need to make changes to the names of all "xls*" as well and change them all into ".xlsx". Preferably with out opening any of them. I want to avoid opening any files due to bandwidth issues (Net is soooooooooo slow here).
any help is greatly appreciated.
thanks,
rich
Code:
Sub LOOPCHANGE()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Dim strOLDP As String, strOLDN As String, strNEWP As String, strNEWN As String, strEXT As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
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
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myFile = Dir(myPath)
Do While myFile <> ""
strEXT = Right(myFile, Len(myFile) - InStrRev(myFile, "."))
strOLDP = myPath
strOLDN = myFile
strNEWN = Mid(myFile, InStrRev(myFile, "\") + 1, InStrRev(myFile, ".") - InStrRev(myFile, "\") - 1)
Debug.Print strEXT
Debug.Print strOLDN
If Not UCase(Right(strEXT, 1)) = "F" Then
strEXT = ".xlsx"
End If
strNEWN = strNEWN & strEXT
strNEWP = myPath
strNEWN = myFile
Name strOLDP & strOLDN As strNEWP & strNEWN
myFile = Dir
Loop
MsgBox "Task Complete!"
ResetSettings:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
any help is greatly appreciated.
thanks,
rich