barrymahboub
10-05-2012, 07:41 AM
I have some code that can change tif & pdf files to the following format YYMMDD - CR - N, plesae see code. The problem is if pressed twice it duplicates I need a way of stopping the duplication. Many thanks.
Sub ChangeFilename()
'"R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\test\"
Dim strfile As String, fileext As String, filepath As String, filenum As String 'My variables
filepath = BrowseForFolder("R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\") & "\"
strfile = Dir(filepath)
Do While strfile <> ""
Debug.Print strfile
Call MyCheck
If Right$(strfile, 3) = "tif" Or Right$(strfile, 3) = "pdf" Then
filenum = Left(strfile, Len(strfile) - 4)
fileext = Right(strfile, 3)
'End of each file name with - Cr -N
Name filepath & strfile As filepath & filenum & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
strfile = Dir
Loop
End Sub
Sub ChangeFilename()
'"R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\test\"
Dim strfile As String, fileext As String, filepath As String, filenum As String 'My variables
filepath = BrowseForFolder("R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\") & "\"
strfile = Dir(filepath)
Do While strfile <> ""
Debug.Print strfile
Call MyCheck
If Right$(strfile, 3) = "tif" Or Right$(strfile, 3) = "pdf" Then
filenum = Left(strfile, Len(strfile) - 4)
fileext = Right(strfile, 3)
'End of each file name with - Cr -N
Name filepath & strfile As filepath & filenum & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
strfile = Dir
Loop
End Sub