reading the subject line of a new email in outlook 2007

  • Thread starter Thread starter evandelagrammaticas
  • Start date Start date
E

evandelagrammaticas

Good Morning All,

I am fairly new to Outlook VBA programming, and suspect that what I am
trying to do is fairly novice. I am trying to read the subject, to
email address, cc email fields and body of a new email that I am
creating before I send it.

The button that envokes the macro is embedded in the new email
template. I tried the code below to read the subject of the email, but
it gave me no results. Any help would be greatly appreciated.

Dim oMail As Outlook.MailItem
Dim sSubject As String
Set oMail = Application.ActiveInspector.CurrentItem
sSubject = oMail.Subject

MsgBox ("TEST: " & CStr(sSubject))

Cheers,

Evan
 
So your button is there on a custom Outlook email form? Is it a form type
button that's there?

Where is the code executing, is it in the form code? Is your custom form
published?

If this is running as form code then it is VBScript and not VBA code. That
means that you cannot use As clauses and to access the item in the form you
use the Item object. So if this is form code the Click handler for that
button would look like this:

MsgBox ("TEST: " & CStr(Item.Subject)
 
Back
Top