Consulting

Results 1 to 5 of 5

Thread: MyCheck Fuction

  1. #1

    MyCheck Fuction

    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

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Change:
    Call MyCheck
    to:
    If Not MyCheck(strfile) Then
    add an:
    End If
    next to the existing one
    then add the MyCheck function to your code:[vba]Function MyCheck(TheFileName) As Boolean
    If InStr(TheFileName, "-CR-") > 0 And InStr(TheFileName, "-N.") > 0 Then MyCheck = True
    End Function
    [/vba]This will fail to change a file name if it happens already to have both "-CR-" and "-N." in it, but I'd like to hope this is very unlikely unless it has already been changed.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    Barrymahboub

    Thank ever so much for replying it does work and I appologise for not answering sooner, I had one of those weekends were the house hold has gone down with a sickness bug.

  4. #4
    Thank ever so much for replying it does work and I appologise for not answering sooner, I had one of those weekends were the house hold has gone down with a sickness bug.

  5. #5

    File Name Change

    Quote Originally Posted by p45cal
    Change:
    Call MyCheck
    to:
    If Not MyCheck(strfile) Then
    add an:
    End If
    next to the existing one
    then add the MyCheck function to your code:[vba]Function MyCheck(TheFileName) As Boolean
    If InStr(TheFileName, "-CR-") > 0 And InStr(TheFileName, "-N.") > 0 Then MyCheck = True
    End Function
    [/vba]This will fail to change a file name if it happens already to have both "-CR-" and "-N." in it, but I'd like to hope this is very unlikely unless it has already been changed.

Posting Permissions

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