barrymahboub
10-09-2012, 12:53 AM
Hi everyone I could do with some urgent help, I have a piece of code that changes tif & pdf file names to example from 47892 to 4789200001-CR- N but I need it to erase the number so it lends up like 000001-CR-N and the next file 000002-CR-N and so on. If some body could help that would be great :yes
Here is the code.
Option Explicit
Function MyCheck(TheFileName) As Boolean
If InStr(TheFileName, "-CR-") > 0 And InStr(TheFileName, "-N.") > 0 Then MyCheck = True
End Function
Sub ChangeFilename()
Dim strfile As String, fileext As String, filepath As String, filenum As String, n As Integer 'My variables
filepath = BrowseForFolder("R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\") & "\"
strfile = Dir(filepath)
Do While strfile <> ""
Debug.Print strfile
'Check that filename is Isnumeric
If Not MyCheck(strfile) Then
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 & Format(n, "1") + 1 & "." & fileext
Name filepath & strfile As filepath & filenum & Format(n, "000001") & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
End If
strfile = Dir
Loop
End Sub
Here is the code.
Option Explicit
Function MyCheck(TheFileName) As Boolean
If InStr(TheFileName, "-CR-") > 0 And InStr(TheFileName, "-N.") > 0 Then MyCheck = True
End Function
Sub ChangeFilename()
Dim strfile As String, fileext As String, filepath As String, filenum As String, n As Integer 'My variables
filepath = BrowseForFolder("R:\DFS\Strategy and Compliance\FINEST\Projects\Imaging Trial\Documents\Creditors\") & "\"
strfile = Dir(filepath)
Do While strfile <> ""
Debug.Print strfile
'Check that filename is Isnumeric
If Not MyCheck(strfile) Then
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 & Format(n, "1") + 1 & "." & fileext
Name filepath & strfile As filepath & filenum & Format(n, "000001") & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
End If
strfile = Dir
Loop
End Sub