Link to home
Start Free TrialLog in
Avatar of shanepresley
shanepresley

asked on

Outlook Macro to send email

I am using Outlook 2002, and would like to create a macro.  I need the macro to modify the currently open email, rewrite the subject line, then send it.

I've already got the code for the subject line modification.  But how do I instruct Outlook to then send the message?


Sub ms()
Set objItem = Application.ActiveInspector.CurrentItem
objItem.Subject = "TEST " & objItem.Subject
End Sub

Open in new window

Avatar of David Lee
David Lee
Flag of United States of America image

Hi, shanepresley.

You have to create a new message reply, or forward in order to send a message.  You cannot send the currently open message as is.  Try this
Sub ms()
    Dim olkMsg As Outlook.MailItem
    Set objItem = Application.ActiveInspector.CurrentItem
    Set olkMsg = objItem.Forward
    With olkMsg
        .Subject = "TEST " & objItem.Subject
        .Recipients.Add "someone@address.com"
        .Send
    End With
    Set olkMsg = Nothing
End Sub

Open in new window

Avatar of shanepresley
shanepresley

ASKER

Hmm that's a bit of a problem.  I was hoping to let the user compose a new message or reply on their own, then the new macro would modify the subject, then send.

No way to accomplish this?
Sorry, if the message that's open is already a new message, reply, or forward, then it's not necessary to create another.  If that's the case, then this is what you want
Sub ms()
    Set objItem = Application.ActiveInspector.CurrentItem
    With objItem
        .Subject = "TEST " & .Subject
        .Send
    End With
End Sub

Open in new window

Excellent, getting closer!  That worked, thanks!  But outlook gives the user a warning, saying that a program is trying to send a message on your behalf.  Any way around that?  
warning.jpg
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent help, thank you!
You're welcome.  Glad I could be of service.