-
FileName
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.
[VBA]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[/VBA]
-
[VBA]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
Dim filepath As String, filenum As String, n As Long '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
n = n + 1
Name filepath & strfile As filepath & filenum & Format(n, "000000") & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
End If
strfile = Dir
Loop
End Sub[/VBA]
-
Still not coming out quite right.
Out come
47892000011-CR- N.tif and 267632000021-CR-121009-N.tif
But I need
I need 000001-CR-N.tif and 000002-CR-N.tif
-
Correction the out come is 47892000001- CR-N.tif and 267632000002-CR-N.tif but I need I need 000001-CR-N.tif and 000002-CR-N.tif
-
Needs to erase the original file name
-
I saw you say that, but your code said otherwise
[VBA]Sub ChangeFilename()
Dim strfile As String, fileext As String
Dim filepath As String, filenum As String, n As Long '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
n = n + 1
Name filepath & strfile As filepath & Format(n, "000000") & "-CR-" & Format(Now(), "YYMMDD") & "-N" & "." & fileext
End If
End If
strfile = Dir
Loop
End Sub[/VBA]