PDA

View Full Version : Solved: How to check event in inbox ?



separator
03-22-2005, 04:36 AM
Hello!
How to check in Vba macro event in Outlook ?
I need check if it selected or not message's in inbox folder. And if yes change some fields in it.
Thanx!

Killian
03-24-2005, 03:18 AM
Not sure what you mean exactly here, but the easiest way to check messages in the Inbox is to use a Rule. If you need to run some code once you have used the rule to select a message, write a macro in the VBEditor that is passed a reference to a mail message e.g: Sub Test(Item As Outlook.MailItem)
'do some stuff
End Sub
then choose "run a script" in your rule action and click the link to select your macro

separator
03-31-2005, 06:20 AM
So, it's example from outlook help: I just try to add extra line to change a user difined field in all recieved letters that I selected. But actualy it change only first selected letter.
How just change field for all letters ?


Sub newtest()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
MsgTxt = "You have selected items from" & Chr(13) & Chr(13)
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & Chr(13)
'extra line
myOlSel.Item(x).UserProperties.Item("My storage Number") = "111"
Next x
MsgBox MsgTxt
End Sub


Thanx

Killian
03-31-2005, 08:30 AM
very strange... I don't understand why it applies to the first one only. I made it work by saving each mail item afterwards. Also, you should "Add" the userproperty'declare a variable fro mailitems
Dim myItem As MailItem

'loop through all the items in the selection
For Each myItem In myOlSel
myItem.UserProperties.Add("My storage Number", olText) = "111"
myItem.Save 'save it!
Next

separator
04-01-2005, 05:22 AM
Thanx Killian! - it's working!

separator
04-19-2005, 05:45 AM
Hi!
The same question, just another event :)
"Ssomebody change data in UserDefinedField in letter"
How to catch it ?
And maybe it present some library for event in outlook ?