AnsweredAssumed Answered

Help making code more efficient

Question asked by David Dewey on Feb 15, 2017
Latest reply on Mar 23, 2017 by Scott Stuart

Hoping someone can offer me some assistance.

 

I'm currently using the following snippet to delete files from a directory. Right now, I'm looking for an explicit filename. However, I would like something  closer to   KillFilePDF = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & ***<----ANY TEXT AFTER THIS*** ".PDF"

The filename for after the IMPN variable always contains a space before it if it has a revision. I'm currently looking through Revision F, but I would like to change this to delete ANY revision level file that lives out there.

 

'DELETE EXISTING PDF AND DWG FILES FROM SALES FOLDER, REGARDLESS OF REVISION AND CERT SUFFIXES

    Dim KillFilePDF As String

        KillFilePDF = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & ".PDF"

        Debug.Print KillFilePDF

        'Check that file exists

        If Len(Dir$(KillFilePDF)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDF, vbNormal

            'Then delete the file

            Kill KillFilePDF

        End If

    Dim KillFilePDFREVA As String

        KillFilePDFREVA = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV A.PDF"

        Debug.Print KillFilePDFREVA

        'Check that file exists

        If Len(Dir$(KillFilePDFREVA)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVA, vbNormal

            'Then delete the file

            Kill KillFilePDFREVA

        End If

    Dim KillFilePDFREVB As String

        KillFilePDFREVB = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV B.PDF"

        Debug.Print KillFilePDFREVB

        'Check that file exists

        If Len(Dir$(KillFilePDFREVB)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVB, vbNormal

            'Then delete the file

            Kill KillFilePDFREVB

        End If

    Dim KillFilePDFREVC As String

        KillFilePDFREVC = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV C.PDF"

        Debug.Print KillFilePDFREVC

        'Check that file exists

        If Len(Dir$(KillFilePDFREVC)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVC, vbNormal

            'Then delete the file

            Kill KillFilePDFREVC

        End If

    Dim KillFilePDFREVD As String

        KillFilePDFREVD = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV D.PDF"

        Debug.Print KillFilePDFREVD

        'Check that file exists

        If Len(Dir$(KillFilePDFREVD)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVD, vbNormal

            'Then delete the file

            Kill KillFilePDFREVD

        End If

     Dim KillFilePDFREVE As String

        KillFilePDFREVE = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV E.PDF"

        Debug.Print KillFilePDFREVE

        'Check that file exists

        If Len(Dir$(KillFilePDFREVE)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVE, vbNormal

            'Then delete the file

            Kill KillFilePDFREVE

        End If

    Dim KillFilePDFREVF As String

        KillFilePDFREVF = "M:\Public - Sales\Email Drawings" & "\" & IMIPN & " REV F.PDF"

        Debug.Print KillFilePDFREVF

        'Check that file exists

        If Len(Dir$(KillFilePDFREVF)) > 0 Then

            'First remove readonly attribute, if set

            SetAttr KillFilePDFREVF, vbNormal

            'Then delete the file

            Kill KillFilePDFREVF

        End If

Outcomes