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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with a selected email in Outlook 1

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
Hi

I use the code below to select an email in my inbox and carry out various tasks with it. At present I choose the email I want to work with by "ticking" it as "Complete" and then running the code from a button in a form. The code works by checking each email in turn and using the one with "FlagStatus = olFlagComplete". My query is, is there a way of using code to simply choose the email which is highlighted in my inbox rather than using the "Complete" flag (as other users of my database use this flag to manage their emails). Basically I need something to replace the "If temp.Items(I).FlagStatus = olFlagComplete" statement. I tried using things like "If temp.Items(I).IsSelected = TRUE", and also using color categories but they didn't work. Any help would be greatly appreciated.

Many thanks

AL

Code:
Dim ns As Outlook.Namespace
   Dim sent As Outlook.MAPIFolder
   Dim temp As Outlook.MAPIFolder
   Dim I As Integer
   Dim J As Integer
   Dim email As MailItem
   Dim att As Attachment
   Dim emailname As String
   
   Set ns = GetNamespace("MAPI")
   Set temp = ns.GetDefaultFolder(olFolderInbox)
      
   For I = temp.Items.Count To 1 Step -1
                   
   If temp.Items(I).Class <> 43 Then GoTo nexti:
                      
   If temp.Items(I).FlagStatus = olFlagComplete Then
'etc.
 
To get the currently selected e-mail, all you need to do is ...

Code:
[blue][indent]Dim oOutlook     As Outlook.Application
Dim email        As Outlook.MailItem
Set oOutlook = New Outlook.Application
Set email = oOutlook.ActiveExplorer.Selection(1)[/indent][/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Many thanks Tony. Works a treat. Much appreciated.

AL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top