Copy file to another folder if an error exist

Currently I have multiple excel files in a directory, each consisting of multiple transaction records.
When one of the transaction records doesn’t match with what we have in the system, we highlight the corresponding transaction’s row in the excel.

What I need help with is:

  1. Within the for each file loop, when the current file being processed has an error and got highlighted, copy that excel file to the directory specifically for saving those error files

  2. Attach all those excel files to outlook mail after the for each loop is finished

Please help, thank you.

Hello @Joanne_Chang_LAX, try something like this:

  • Assign originalFolderPath = “C:\Path\To\Original\Files”

  • Assign errorFilesFolderPath = “C:\Path\To\Error\Files”

  • Assign outlookRecipient = “recipient@example.com

  • For Each file In Directory.GetFiles(originalFolderPath)

    • Use Excel activities to read and process the Excel file
    • Check if there are highlighted rows indicating errors
    • If errors found
      • Assign newFilePath = Path.Combine(errorFilesFolderPath, Path.GetFileName(file))
      • File.Copy(file, newFilePath, True)
  • Use Outlook activities to send an email

    • To: outlookRecipient
    • Subject: “Error Files”
    • Body: “Please find attached error files.”
    • Attachments: Directory.GetFiles(errorFilesFolderPath)

Cheers!! :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.