none
Outlook ( 2007 ) macro - - delete the first row from the attached Excel workbooks in the Outlook "Inbox." RRS feed

  • Question

  • I'm wondering if it's possible to use VBA in Outlook to open all of the Excel workbooks that are attached to the e-mails in the Outlook "Inbox" and then delete the first row in each of the attachments?

         If it's possible, could you provide a sample of the code that would accomplish the task?

    Thanks,

    Jim


    • Edited by jim_one Tuesday, November 24, 2015 3:22 AM Updated my question.
    Monday, November 23, 2015 9:16 PM

Answers

  • Hi Jim,

    >> I'm wondering if it's possible to use VBA in Outlook to open all of the Excel workbooks that are attached to the e-mails in the Outlook "Inbox" and then delete the first row in each of the attachments?

    Yes, you could. To achieve your requirement, you could download your attachments, modify the excel files, remove the exist attachments, and then add new attachments.

    For adding the modified excel files, you could use Attachments.Add, here is a simple code for adding excel files:

    Sub SelectedItem()
    Dim Item As MailItem
    Dim SelectedItems As Selection
    
    Set SelectedItems = Outlook.ActiveExplorer.Selection
    For Each Item In SelectedItems
        With Item
          Item.Subject = "test"
          Item.Attachments.Add "C:\Users\Desktop\1.xlsx"
        End With
    Next Item
    End Sub
    

    # Attachment Object (Outlook)
    https://msdn.microsoft.com/EN-US/library/office/ff863918.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 25, 2015 8:21 AM

All replies

  • Hi Jim,

    >> I'm wondering if it's possible to delete a row from all of the Excel workbooks that are attached to the e-mails in the Outlook "Inbox?"

    What do you want to deal with the excel files which have been delete a row?
    If you want to save the excel file and delete the row, it is possible. You could follow the steps below:

    1. Loop the e-mails and save the attachments.
    # Outlook - VBA code to download email (Excel)attachment
    https://social.msdn.microsoft.com/Forums/en-US/fa809869-4cfb-4f0b-a2eb-b6e5eaf0f094/outlook-vba-code-to-download-email-excelattachment?forum=isvvba

    2. Delete the row in the excel file
    # VBA - Delete Row If
    https://social.msdn.microsoft.com/Forums/en-US/29fccbfe-4451-4f41-ad5b-d4d93dc3196c/vba-delete-row-if?forum=exceldev

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, November 24, 2015 2:21 AM
  • Hi Jim,

    >> I'm wondering if it's possible to use VBA in Outlook to open all of the Excel workbooks that are attached to the e-mails in the Outlook "Inbox" and then delete the first row in each of the attachments?

    Yes, you could. To achieve your requirement, you could download your attachments, modify the excel files, remove the exist attachments, and then add new attachments.

    For adding the modified excel files, you could use Attachments.Add, here is a simple code for adding excel files:

    Sub SelectedItem()
    Dim Item As MailItem
    Dim SelectedItems As Selection
    
    Set SelectedItems = Outlook.ActiveExplorer.Selection
    For Each Item In SelectedItems
        With Item
          Item.Subject = "test"
          Item.Attachments.Add "C:\Users\Desktop\1.xlsx"
        End With
    Next Item
    End Sub
    

    # Attachment Object (Outlook)
    https://msdn.microsoft.com/EN-US/library/office/ff863918.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 25, 2015 8:21 AM
  • It's not clear to me. Should step 2 be in the Outlook VBA moduleor in an Excel VBA module?

    Tuesday, August 8, 2017 3:37 PM