Consulting

Results 1 to 6 of 6

Thread: Solved: How to check event in inbox ?

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location

    Question Solved: How to check event in inbox ?

    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!

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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: [VBA]Sub Test(Item As Outlook.MailItem)
    'do some stuff
    End Sub
    [/VBA] then choose "run a script" in your rule action and click the link to select your macro
    K :-)

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    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 ?


    [vba]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[/vba]


    Thanx

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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[VBA]'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[/VBA]
    K :-)

  5. #5
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Thanx Killian! - it's working!

  6. #6
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    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 ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •