title: VB Script Error - Worked before but now not confusingly
body: <p>i am getting a error</p>
  
  <p><img src="https://i.stack.imgur.com/jO5hv.png" alt="Error i am getting"></p>
  
  <p>The VB file reads col1 and finds the matching image name in the directory and the renames that file to col2 it produces a report to show what images haven't been renamed and placed the ones that have in a folder called rename</p>
  
  <p>i have attached the code so you can see</p>
  
  <pre><code>strDocMap = "C:\img\DocMap.xlsx"
  strInputFolder = "C:\img\"
  strOutputFolder = "C:\img\renamed\"
  strLogFile = "C:\img\RenamingLog.txt" 
  strPattern = "\d{5}"
  
  Set regExpression = New RegExp
  With regExpression
  .Global = True
  .IgnoreCase = True
  .Pattern = strPattern
  End With
  Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = True
  Const xlUp = -4162
  Const xlFormulas = -4123
  Const xlPart = 2
  Const xlByRows = 1
  Const xlNext = 1
  Set objWB = objExcel.Workbooks.Open(strDocMap, False, True)
  Set objSheet = objWB.Sheets(1)
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  If Right(strInputFolder, 1) &lt;&gt; "\" Then strInputFolder = strInputFolder &amp; "\"
  If Right(strOutputFolder, 1) &lt;&gt; "\" Then strOutputFolder = strOutputFolder &amp; "\"
  
  If objFSO.FolderExists(strOutputFolder) = False Then objFSO.CreateFolder strOutputFolder
  Set objLog = objFSO.CreateTextFile(strLogFile, True)
  objLog.WriteLine "Script started " &amp; Now
  objLog.WriteLine "Enumerating files in folder: " &amp; strInputFolder
  objLog.WriteLine "Renaming files to folder: " &amp; strOutputFolder
  objLog.WriteLine String(80, "=")
  
  For Each objFile In objFSO.GetFolder(strInputFolder).Files
  Set colMatches = regExpression.Execute(objFile.Name)
  If colMatches.Count &gt; 0 Then
      If colMatches.Count = 1 Then
          For Each objMatch In colMatches
              strOldNum = objMatch.Value
              Set objCell = objSheet.Cells.Find(strOldNum,         objSheet.Range("A1"), xlFormulas, xlPart, xlByRows, xlNext, False, False)
              If Not objCell Is Nothing Then
                  strNewNum = objCell.Offset(0, 1).Value
                  If strNewNum &lt;&gt; "" Then
                      strNewPath = strOutputFolder &amp; strNewNum &amp; "." &amp; objFSO.GetExtensionName(objFile.Path)
                      ' Check if a file already exists without the appended letter
                      blnValid = True
                      If objFSO.FileExists(strNewPath) = True Then
                          blnValid = False
                          ' Start at "a"
                          intLetter = 97
                          strNewPath = strOutputFolder &amp; strNewNum &amp; Chr(intLetter) &amp; "." &amp; objFSO.GetExtensionName(objFile.Path)
                          Do While objFSO.FileExists(strNewPath) = True
                              intLetter = intLetter + 1
                              strNewPath = strOutputFolder &amp; strNewNum &amp; Chr(intLetter) &amp; "." &amp; objFSO.GetExtensionName(objFile.Path)
                              If intLetter &gt; 122 Then Exit Do
                          Loop
                          If intLetter &lt;= 122 Then blnValid = True
                      End If
                      If blnValid = True Then
                          objLog.WriteLine "Renaming " &amp; objFile.Name &amp; " to " &amp; Mid(strNewPath, InStrRev(strNewPath, "\") + 1)
                          objFSO.MoveFile objFile.Path, strNewPath
                      Else
                          objLog.WriteLine "Unable to rename " &amp; objFile.Name &amp; ". Letters exhausted."
                      End If
                  End If
              End If
          Next
      Else
          objLog.WriteLine objFile.Name &amp; " contains " &amp; colMatches.Count &amp; " matches. Manual adjustment required."
      End If
  End If
  Next
  objLog.WriteLine String(80, "=")
  objLog.WriteLine "Script finished " &amp; Now
  objWB.Close False
  objExcel.Quit
  
  objLog.Close
  MsgBox "Done"
  </code></pre>
  
  <p>Thanks</p>
  
  <p>Jack</p>