Macro to add a word in Subject Line

Walter K.

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I'm trying to create a macro in Outlook that will allow me to enter a word on the Subject Line in a new email. I'm extremely limited in VB, usually use record in Excel & Word. I've seen many threads herein but it just isn't clicking for me. What I'm trying to do is create the macro then use a macro button on the ribbon to click on it and enter the word automatically. Sounds simple but all the code I've seen doesn't seem to do it for me. Any help would be appreciated.

Thanks
 

erichamion

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
This should do it, as long as you want to always create a new message. If you want to change the subject on a message that's currently open, there would be a bit more to it.

Alternatively, just start an email with the appropriate subject, and save the message as a template. Then there's no need to bother with VBA or with macro security settings.

Code:
Sub TestMacro() 
    'Set up variables.  Only one is needed here. 
    'objMail will hold our email message. 
    Dim objMail As Outlook.MailItem
  'Application is where everything comes from.  Use the 
    'built-in Application object to create a new item.  olMailItem 
    'is just a number that tells Application what kind of item 
    'to create. 
    Set objMail = Application.CreateItem(olMailItem)
  'Set the subject to the desired text. 
    objMail.subject = "Fancy new subject: "
  'Now the email has been created, and the subject has been set, 
    'but it's invisible.  The last thing we need to do is show it 
    'to the user. 
    objMail.Display
  'Clean up. 
    Set objMail = Nothing 
End Sub
 
Top