0

I am creating a macro to resend email messages. All you have to do is select the email and click the macro button and the email is sent. Everything works fine except to the fact that the original message(s) get deleted or get moved to the sent items folder.

How do i prevent the message from being deleted? I just want a copy to the "sent items" folder. I do not want to delete the original message.

Here is the macro:

Sub ResendThis()

Dim objSelection   As Outlook.Selection
Dim myItem         As Outlook.MailItem
Dim objActionsMenu As Office.CommandBarControl
Dim olResendMsg    As Outlook.MailItem

Set objSelection = Application.ActiveExplorer.Selection

On Error Resume Next

For Each myItem In objSelection
    myItem.Display
    Set olResendMsg      = Application.ActiveInspector.CurrentItem
    olResendMsg.Subject  = "EMAIL RESEND TEST"
    olResendMsg.HTMLBody = "EMAIL CONTENT" & myItem.HTMLBody
    olResendMsg.Send
    myItem.Close olDiscard
Next

Set myItem = Nothing
Set objActionsMenu = Nothing
Set olResendMsg = Nothing

End Sub

The "Send" Method sometimes moves the message to the "sent items" folder and Sometimes the message simply disappears.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
winteck
  • 417
  • 2
  • 4
  • 18
  • It looks like you're updating the original email (not a copy), and then discarding it at the end of the send process. Is it possible that the email disappearing as an unintended outcome of using olDiscard in closing the item, rather than olSavel (and I get btw you're probably not wanting to update the original email)? Can I suggest that you create a second MailItem and use (something like) Set NewMailItem = myItem.Copy and then finish the processing based on NewMailItem, – TechnoDabbler Oct 07 '18 at 23:36
  • Use ‘reply’ or ‘forward’ and you have error in your code so remove on error resume- – 0m3r Oct 08 '18 at 06:53

1 Answers1

0

As Techno said, you can use olResendMsg = myItem.Copy and then finish the processing based on olResendMsg

You can refer to the code below:

Sub ResendThis()

Dim objSelection   As Outlook.Selection
Dim myItem         As Outlook.MailItem
Dim objActionsMenu As Office.CommandBarControl
Dim olResendMsg    As Outlook.MailItem
Set objSelection = Application.ActiveExplorer.Selection

On Error Resume Next

For Each myItem In objSelection
    myItem.Display
    Set olResendMsg = myItem.Copy
    olResendMsg.subject = "EMAIL RESEND TEST"
    olResendMsg.HTMLBody = "EMAIL CONTENT" & myItem.HTMLBody
    olResendMsg.To = "text@outlook.com"
    olResendMsg.CC = ""
    olResendMsg.Send
    myItem.Close olDiscard

Next

Set myItem = Nothing
Set objActionsMenu = Nothing
Set olResendMsg = Nothing

End Sub
Evanzheng
  • 191
  • 4
  • 1
    Try not to add more examples of misuse of `On Error Resume Next` into the world. https://stackoverflow.com/questions/31753201/vba-how-long-does-on-error-resume-next-work/31753321#31753321 – niton Oct 08 '18 at 13:35