Link to home
Start Free TrialLog in
Avatar of SAbboushi
SAbboushiFlag for United States of America

asked on

How to figure out the name of Outlook 2007 MailItem fields and how to reference them in VBA

Having a tough time with concepts and how to reference fields...

Someone refered me to MSDN but I am clueless...

I manually fill in the "From:" and "bcc" fields constantly.  I want to set these fields with default values e.g. "abc@xyz.com"

How do I quickly figure out the names of the From and bcc fields, how to reference them, etc...?  I don't know whether to look in the MAPI reference, or the Developer reference, or... (and isn't there an object browser or something like that which can help make it easier?)

Note: to see the "From:" field, you need to set Outlook to display it (same with bcc field):  
To display these fields, create a new e-mail message, select Options; in the Fields section, click on "Show From" and "Show bcc".

I am seeking the lines of code to set these 2 fields of a reply message to "abc@xyz.com"

And if your name is Chris Bottomley, even better ; )
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Is the from you want to use an account established in outlook or something else entirely ... and if something else I have to ask is it legit?

If it is an account in outlook then can do ... if it isn't then not so much but we can set the reply address.

Chris
Avatar of SAbboushi

ASKER

Not an account and yes it is legit ; )

By filling in the From: field manually, it overrides the reply-to e-mail address for the recipient: the recipient sees "From Sam [mailto:Sam@xyz.com] On Behalf Of abc@xyz.com"

When the recipient clicks on 'Reply', the reply-to e-mail address becomes 'abc@xyz.com' even though 'Sam@xyz.com' is 'account' e-mail address

In that case fine you are looking at the reply to I was thinking about:

See the three modified subs below, the replyrecipients is the same as you show above for on behalf of ... the reply goes in this case to norm"norman.com ... you might want to edit that though ;o)

Chris
Private Sub myItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Response.Subject = Response.Subject & "X"
'    Response.SendUsingAccount = Application.Session.Accounts("me@my.com")
    Response.ReplyRecipients.Add "norm@norman.com"
    Response.BCC = "doris@doris.com"
End Sub

Private Sub myItem_Forward(ByVal Forward As Object, Cancel As Boolean)
    Forward.Subject = Forward.Subject & "X"
'    Response.SendUsingAccount = Application.Session.Accounts("me@my.com")
    Response.ReplyRecipients.Add "norm@norman.com"
    Response.BCC = "doris@doris.com"
End Sub

Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean)
    Response.Subject = Response.Subject & "X"
'    Response.SendUsingAccount = Application.Session.Accounts("me@my.com")
    Response.ReplyRecipients.Add "norm@norman.com"
    Response.BCC = "doris@doris.com"
End Sub

Open in new window

OOPS!

The forward sub is a different object ... corrected here.

Chris
Private Sub myItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Response.Subject = Response.Subject & "X"
'    Response.SendUsingAccount = Application.Session.Accounts("me@mine.com")
    Response.ReplyRecipients.Add "norm@norman.com"
    Response.BCC = "doris@doris.com"
End Sub

Private Sub myItem_Forward(ByVal Forward As Object, Cancel As Boolean)
    Forward.Subject = Forward.Subject & "X"
'    Forward.SendUsingAccount = Application.Session.Accounts("me@mine.com")
    Forward.ReplyRecipients.Add "norm@norman.com"
    Forward.BCC = "doris@doris.com"
End Sub

Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean)
    Response.Subject = Response.Subject & "X"
'    Response.SendUsingAccount = Application.Session.Accounts("me@mine.com")
    Response.ReplyRecipients.Add "norm@norman.com"
    Response.BCC = "doris@doris.com"
End Sub

Open in new window

Forward button results in 'Object required' run-time error... problem with

    Response.ReplyRecipients.Add "norm@norman.com"

Open in new window


Also, is there a more reliable way to set m_Inspectors?  Any problems (such as this one) requires that I manually run application_startup after I see that the code isn't working anymore

Bigger problem: "From:" field is not being set (bcc works great - thanks!)

Found it: Response.SentOnBehalfOfName for "From:" field

Still don't have solution for Forward button...
replyrecipients ought to work, but forward will be forward.sentonbehalfofname ...

Chris
thanks - I will try that

You've made it easier for me by providing the field names - thanks.  Can you tell me how I can find them myself for next time?  My noob approach is highly time-intensive!  

I've read about an object browser & msdn... what is the best resource to help me identify the field references I want (other than Chris!)?   ; )
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland 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
Great - thanks again!