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 ; )
SAbboushiAsked:
Who is Participating?
 
Chris BottomleyConnect With a Mentor Software Quality Lead EngineerCommented:
You've done fine yourself withsentonbehalf...

In the VBE the object browser is displayed via the F2 key but ... try the models via MS themselves at:

http://msdn.microsoft.com/en-us/library/bb176619(v=office.12).aspx

Chris
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
0
 
SAbboushiAuthor Commented:
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

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
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

0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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

0
 
SAbboushiAuthor Commented:
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!)
0
 
SAbboushiAuthor Commented:

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

Still don't have solution for Forward button...
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
replyrecipients ought to work, but forward will be forward.sentonbehalfofname ...

Chris
0
 
SAbboushiAuthor Commented:
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!)?   ; )
0
 
SAbboushiAuthor Commented:
Great - thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.