Results 1 to 6 of 6

Thread: FileName

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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
    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]
    Last edited by Bob Phillips; 10-09-2012 at 12:56 AM. Reason: Added VBA tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •