Here is a simplification of the relevant parts of your code. You can
merge with whatever other code you deem necessary. This will rename the
file and move it per your code spec. I left out extension verification
because I felt it unnecessary.
Please note, the correct method of working with current date and time to
to first store them in a variable, and then work with the variable
because it will not change while the script is running. This code has
not been tested with UNC paths. You will have to do that on your end.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objshell = CreateObject("Wscript.shell")
'On Error Resume Next
'Do not use OERN unless error handling code is included
'Get yesterday's date
'-----------------------
d = Date - 1
strMonth = Right("0" & Month(d),2)
strDay = Right("0" & Day(d),2)
strYear = Year(d)
'strHour = Hour(Time)
'strMinute = Minute(Time)
'strSecond = Second(Time)
strPastDay = strYear & strMonth & strDay
'-----------------------
'----------------------------------------------------------------------
'Specify variables for File Paths
strFromPath1 = "C:\CSIeSafeDFX\receive"
strToPath1 = "c:\treasury\Public funds\"
'Specify variable for original Filename prefix and new name
strFile1 = "DFX_Loans Past Due by PDR" ' *.xls
strNewFile1 = "DFX_LoansPastDueByPDR" & strPastDay & ".xls"
'----------------------------------------------------------------------
Set f = objFSO.GetFolder(strFromPath1)
Set fc = f.Files
moved = false
For Each f1 in fc
s =
f1.name
If Left(Ucase(s),Len(strFile1)) = Ucase(strFile1) Then
f1.Name = strNewFile1
objFSO.MoveFile f1.Path, strToPath1
moved = True
Exit For
End If
Next
If moved Then
MsgBox "File [" & strFile1 & "*.*] renamed and moved to [" & _
strToPath1 & "\" & strNewFile1 & "].", vbInformation
Else
MsgBox "File [" & strFile1 & "*.*] not found.", vbExclamation
End If
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)