Hi,
The Background: I have a desktop flow which pulls downloads an excel file and saves it to my local drive. I receive similar file each day (same number and title of columns) which, so far, I have been able to save using a datestamp for each file.
Context Reference: As of now, this is the code I have been using to execute my flow successfully
Outlook.Launch Instance=> OutlookInstance
Outlook.RetrieveEmailMessages.RetrieveEmailsAndSaveAttachments Instance: OutlookInstance Account: $'''xyz@outlook.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: True ReadBodyAsHtml: False SubjectContains: $'''XYZ Report''' SaveAttachmentsInto: $'''Z:\\XYZ\\ABC''' Messages=> RetrievedEmails
LOOP FOREACH CurrentEmail IN RetrievedEmails
LOOP FOREACH CurrentAttachment IN CurrentEmail.Attachments
IF Contains(CurrentAttachment.Extension, $'''xlsx''', False) THEN
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''MMddyyyy''' Result=> FormattedDateTime
File.RenameFiles.Rename Files: CurrentAttachment NewName: $'''%CurrentAttachment.NameWithoutExtension%_%FormattedDateTime%%CurrentAttachment.Extension%''' KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
LOOP FOREACH CurrentItem IN RenamedFiles
Excel.LaunchExcel.LaunchAndOpen Path: CurrentItem Visible: True ReadOnly: False LoadAddInsAndMacros: False Instance=> ExcelInstance
DISABLE Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: RenamedFiles
# Set the correct Sheet name here from where you want to delete the rows.
SET RowCounter TO 1
LOOP WHILE (RowCounter) <= (3)
Excel.DeleteRow Instance: ExcelInstance Index: 1
Variables.IncreaseVariable Value: RowCounter IncrementValue: 1
END
Excel.CloseExcel.CloseAndSaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''Z:\\XYZ\\ABC\\Dated Reports\\XYZ_report%FormattedDateTime%'''
END
END
END
END
File.Delete Files: RenamedFiles
The Problem: The requirements have changed recently where I would like to add the data from the file that I am receiving each day into one main file. For this purpose, I would have to essentially delete the last two rows from the main file (which contains values like 'total' etc.) and then delete the first row from the new file (which would contain the title of the columns as they would not be needed if the titles are already present in the main file) and finally add the remaining data from the most recent file for download.
Anticipated Solution: I would like to add to my flow so that similar to my current flow, the last two four rows are deleted from the main file on my drive, the first four rows are deleted from the new file being downloaded, and finally the data from the new file is added under the existing rows of my main file.
TIA!