Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook: Get email headers and body

Status
Not open for further replies.

Skute

Programmer
Jul 21, 2003
272
GB
Hi,

is it possible to create a button in Outlook that when pressed can extract information about the selected emails headers + body? Where abouts can i start looking?

Basic info im trying to obtain automatically is:
From
Subject
Body

Thanks.
 
Skute,

What version of outlook are you using.

If you are using outlook 2000 then the following code will work. I have tested this on my machine running Outlook 2000 and it runs just fine.


Sub GetSelectedItem_Click()
' This uses an existing instance if available (default Outlook behavior).
Dim oApp As New Outlook.Application
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection ' You need a selection object for getting the selection.
Dim oItem As MailItem

Set oExp = oApp.ActiveExplorer ' Get the ActiveExplorer.
Set oSel = oExp.Selection ' Get the selection.

For i = 1 To oSel.Count ' Loop through all the currently .selected items
Set oItem = oSel.Item(i) ' Get a selected item.
MsgBox (oItem.SenderName & vbcrlf & oItem.subject & vbcrlf & oItem.Body) ' Display information about it.
Next i
End Sub


You can amend this code to suit your own needs.

HTH




Matt
[rockband]
 
Hi,

thats great, yeah im using Outlook 2000. Where abouts do i stick that code though? Ive never experimented with this before. Do you have a good tutorial link i could look at?

Thanks
 
Oh, ive just got it working.

(Its saved as VBAProject.otm - is there anyway to save that else where?)

Is there anyway to stop outlook from saying "An application is trying to access your emails!"? Its most annoying having to say allow access for 10minutes.

Thanks
 
Skute,

As far as the storage of the macro goes you have got it stored in the best place.

The messages you are getting are more of a problem but there should be a workaround. You should take a look at thread707-620926 for a possible work around.

HTH

Matt
[rockband]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top