Change Cell based on File Rename

48 views Asked by At

First question on here. I am learning VBA and trying to use it for practical work.

I have loads of zip files, and in each zip there is a specific file that I need to extract and rename. I use Excel to list those files and rename them automatically for me. However the file or zip in general aren’t always there.

How can I have Excel (VBA) change the color of a cell that couldn’t successfully rename a file?

Here is my current code:

Sub RenameCNotes()

    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False

        If .Show = -1 Then
            selectDirectory = .SelectItems(1)
            dFileList = Dir(selectDirectory & Application.PathSeparator & “*”)

            Do Until dFileList = “”
                curRow = 0
                On Error Resume Next
                If curRow > 0 Then
                    Name selectDirectory & Application.PathSeparator & dFileList As _
                    selectDirectory & Application.PathSeparator & Cells(curRow, “D”).Value
                End If

                dFileList = Dir
            Loop
        End If
    End With
End Sub
0

There are 0 answers