Results 1 to 4 of 4

Thread: Outlook and bespoke rules

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    UK
    Posts
    21

    Outlook and bespoke rules

    I want to build email rules whereby if I send an email to a specified person that email is placed in a certain folder. The inbuilt rules allow me to copy but not move emails to that folder.

    As a first step to working out how I could do this I found this code on the internet.

    Sub SetFlagIcon()
    Dim mpfInbox As Outlook.Folder
    Dim obj As Outlook.MailItem
    Dim i As Integer
    Set mpfInbox = Session.GetDefaultFolder(olFolderInbox)
    Set mpfInbox = mpfInbox.Folders("Test")
    ' Loop all items in the Inbox\Test Folder
    For i = 1 To mpfInbox.Items.Count
    If mpfInbox.Items(i).Class = olMail Then
    Set obj = mpfInbox.Items.Item(i)
    For Each Recipient In obj.Recipients
    If Recipient.Address = "Name@IP.co.uk" Then
    'Set the yellow flag icon
    obj.FlagIcon = olYellowFlagIcon
    obj.Save
    End If
    Next Recipient
    End If
    Next
    End Sub


    The problem I have is that it's not picking up the email address as being true, I have tested it with "If not Recipient.Address = "Name@IP.co.uk" " and it flags the emails as Yellow.

    So short basic question - any ideas as to what might be wrong?
    Last edited by Peter_B; Dec 11th, 2017 at 11:37 AM. Reason: syntax

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Outlook and bespoke rules

    addresses matches are case sensitive, you could try forcing both to lcase, i tested your posted code and it worked correctly
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Location
    UK
    Posts
    21

    Re: Outlook and bespoke rules

    Thanks, I've now tested it against my home email address which is shown in the format name.surname@IP.com and it works, whereas at work, although we have a the same underlying structural addresses that's always converted to a NAME (Team) label. I've obviously tried this against the standard email construct as above and since tried it against the label but neither is recognised. There's obviously something I'm missing about what is being taken as the email address.

    Wonder if there's a way to ensure it only looks for the underlying email address?

    Peter

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Outlook and bespoke rules

    you could test with .addressentry.address
    as i am only using outlook as stand alone, not with exchange i also can not test
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width