web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Overwrite file from ou...
Power Automate
Answered

Overwrite file from outlook

(0) ShareShare
ReportReport
Posted on by 6

How do I save the excel file from attachment from outlook email to the folder where file with such name already exists. I want to overwrite the file instead of saving a new version. For now when I save a file with the same name, automatically "(2)" is added to the end of the name.

 

 

I have the same question (0)
  • Verified answer
    CU31080729-3 Profile Picture
    502 Moderator on at

    HI Agata_Gaj,

    There is no direct method for download mail attachment from outlook and overwrite to your existing same file.

    you can download attachment to one of the specific folder and then move this file where your same file is already exist, for that you can used move file action and there select option if file exist then overwrite.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Chetan Ninghot

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Agata_Gaj 

     

    Please follow the below suggested actions.

    Instructions:

    1. Launch an instance of Outlook and name it OutlookInstance.
    2. Retrieve email messages using the OutlookInstance.
      • Specify the account as Example : "Deenu@microsoft.com".
      • Choose the mail folder as "Inbox".
      • Set the option to retrieve only unread emails.
      • Mark retrieved emails as read.
      • Filter emails with the subject containing "Product".
      • Specify the folder to save attachments as "C:\Users\Documents"(Example).
      • Save the retrieved emails in a variable named RetrievedEmails.
    3. Start a loop to iterate through each email in RetrievedEmails.
    4. Within the loop, start another loop to iterate through each attachment in the current email.
    5. Check if the extension of the current attachment contains "xlsx" (case insensitive) - You can ignore this step if its not applicable.
    6. If the condition is met, perform the following actions:
      • Get the current local date and time.
      • Format the date and time as "ddMMyyyy".
      • Rename the current attachment file by appending the formatted date and time to its name.
      • Keep the extension of the attachment.
      • If a file with the new name already exists, overwrite it.
    7. End both loops.

     

    Deenuji_0-1713262140314.png

     

     

    Code[Copy and paste the below code to your PAD designer]:

    Outlook.Launch Instance=> OutlookInstance
    Outlook.RetrieveEmailMessages.RetrieveEmailsAndSaveAttachments Instance: OutlookInstance Account: $'''Deenu@microsoft.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: True ReadBodyAsHtml: False SubjectContains: $'''Product''' SaveAttachmentsInto: $'''C:\\Users\Documents''' 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: $'''ddMMyyyy''' Result=> FormattedDateTime
     File.RenameFiles.Rename Files: CurrentAttachment NewName: $'''%CurrentAttachment.NameWithoutExtension%_%FormattedDateTime%%CurrentAttachment.Extension%''' KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
     END
     END
    END

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 269 Super User 2026 Season 2

#2
trice602 Profile Picture

trice602 184 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 136 Super User 2026 Season 2

Last 30 days Overall leaderboard