VBA code to enable a rule based on time of day for a IMAP mail account

Status
Not open for further replies.

Guru

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Ive seen forums discussing rules to enable / disable rules based on time of day and or based on a task trigger using VBA codes, however those only work if teh account is a POP3 accoutn not when its an IMAP account.

Is there any way to get these codes to work on an IMAP account.

----
Sample VBA code on a POP account based on task trigger

Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
Exit Sub
End If
If Item.Subject = "Enable Rule" Then
Enable_Run_Rule
End If
If Item.Subject = "Disable Rule" Then
Disable_Run_Rule
End If
End Sub
' Macro to enable a rule
Sub Enable_Run_Rule()
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Dim intCount As Integer
Dim blnExecute As Boolean

Set olRules = Application.Session.DefaultStore.GetRules
Set olRule = olRules.Item(outofoffice)
olRule.Enabled = True
If blnExecute Then olRule.Execute ShowProgress:=True
olRules.Save

Set olRules = Nothing
Set olRule = Nothing
End Sub
' Macro to disable a rule
Sub Disable_Run_Rule()
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Dim intCount As Integer
Dim blnExecute As Boolean

Set olRules = Application.Session.DefaultStore.GetRules
Set olRule = olRules.Item(outofoffice)
olRule.Enabled = False
If blnExecute Then olRule.Execute ShowProgress:=True
olRules.Save

Set olRules = Nothing
Set olRule = Nothing
End Sub
--

any help is greatly appriciated!!
 
correct, tried to run the code, getting error that it cannot run on this store, tried runing same code on a POP2 account works fine.
 
exact error message i get is

This store does not support rules. Could not complete the operation.
 
Thanks, now I see it. You need to find the imap account in Session.Stores, then call that Store's GetRules function.
 
The imap account is the only account in outlook, how else can i call it besides as i have wrote "Application.Session.DefaultStore"
 
IMAP is the default email account, that's what DefaultStore points to. The rules are stored in the default data file, which must be there if we're talking about OL 2010.
 
its indeed in OL2010,

but i'm not sure what you mean when you wrote "you need to find the imap account in Session.Stores, then call that Store's GetRules function"
 
Instead of calling DefaultStore, get the store by calling Session.Stores(Name).

BTW, I accidentally swapped it, DefaultStore points to the default data file, while the Rules are stored in the default email account. Anyway, that's why DefaultStore doesn't work.
 
i used the below code to get the full Session ID, and then called the SessionStores by the ID to no avail, giving me the same exact error

-- Code used to obtain ID
Public Sub GetListOfStores()
On Error GoTo On_Error

Dim Session As Outlook.NameSpace
Dim Store As Outlook.Store
Dim Stores As Outlook.Stores
Dim Report As String

Set Session = Application.Session

Set Stores = Session.Stores
For Each Store In Stores
Report = Report & Store.DisplayName & vbCrLf
Report = Report & "Location : " & Store.FilePath & vbCrLf
Report = Report & "Is Cached Exchange : " & Store.IsCachedExchange & vbCrLf
Report = Report & "Is Data File Store : " & Store.IsDataFileStore & vbCrLf
Report = Report & "Is Instant Search Enabled : " & Store.IsInstantSearchEnabled & vbCrLf
Report = Report & "Is Open : " & Store.IsOpen & vbCrLf
Report = Report & "Class : " & Store.Class & vbCrLf
Report = Report & "Exchange Store Type : " & Store.ExchangeStoreType & vbCrLf
Report = Report & "Store ID : " & Store.StoreID & vbCrLf & vbCrLf
Next Store

Dim retValue As Boolean
retValue = CreateReportAsEmail("List of Stores", Report)

Exiting:
Set Session = Nothing
Exit Sub
On_Error:
MsgBox "error=" & Err.Number & " " & Err.Description
Resume Exiting
End Sub

Public Function CreateReportAsEmail(Title As String, Report As String)
On Error GoTo On_Error

Dim Session As Outlook.NameSpace
Dim mail As MailItem
Dim MyAddress As AddressEntry
Dim Inbox As Outlook.Folder

CreateReportAsEmail = True

Set Session = Application.Session
Set Inbox = Session.GetDefaultFolder(olFolderInbox)
Set mail = Inbox.Items.Add("IPM.Mail")

Set MyAddress = Session.CurrentUser.AddressEntry
mail.Recipients.Add (MyAddress.Address)
mail.Recipients.ResolveAll

mail.Subject = Title
mail.Body = Report

mail.Save
mail.Display


Exiting:
Set Session = Nothing
Exit Function
On_Error:
CreateReportAsEmail = False
MsgBox "error=" & Err.Number & " " & Err.Description
Resume Exiting
End Function

-
 
Maybe I'm missing anything but that code doesn't call GetRules. Where do you get the error "This store does not support rules"?
 
the code above provides me the full valid store ID, which didnt fix the issue, unless i wasnt correctly using the store ID in calling the session.

If possible can you please type out the full line how i have it and how you woulr have it instead
 
Are you still trying to get the rules, or are we talking about another issue now? Only one of the stores supports rules, for all of the other stores calling GetRules raises an error. If you don't know its name, you can solve it this way:
Code:
on error resume next
for each store in stores
  set rules=store.getrules
  if not rules is nothing then exit for
next
 
still trying to get the rules to work on outlook 2010 using an imap account.

question above asked whihc line of my code do i have to replace to get it to work and what do i replace it with
 
Return to the first code you posted. There see where you call GetRules. Loop through the Stores collection as demonstrated above and ignore the error. One of the GetRules calls will succeed.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D Outlook 2021 Using vba code to delete all my spamfolders not only the default one. Outlook VBA and Custom Forms 0
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
D VBA code to select a signature from the signatures list Outlook VBA and Custom Forms 3
S Excel vba code to manage outlook web app Using Outlook 10
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
S Add VBA save code Using Outlook 0
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
B VBA Code to create appointment from email Outlook VBA and Custom Forms 1
D VBA Code to strip Subject Line when replying or forwarding Using Outlook 3
M VBA Code to Restart Outlook on error Outlook VBA and Custom Forms 3
Z Default VBA code for extracting data from email (Outlook) to Excel? Outlook VBA and Custom Forms 1
T VBA to Sort Rules [A-Z] - code provided Outlook VBA and Custom Forms 9
M VBA Auto-Reply code for Two Mailboxes on one Outlook Session. Outlook VBA and Custom Forms 4
Z Protecting VBA code - anything new? Outlook VBA and Custom Forms 2
S VBA code to rename a task (flagged message) Outlook VBA and Custom Forms 1
M VBA code to save email attachments (PDF) as email subject line Outlook VBA and Custom Forms 1
F VBA Code to change subject Like Outlook VBA and Custom Forms 3
Diane Poremsky Pasting VBA code (and other editing) Outlook VBA and Custom Forms 4
C Required VBA code to complete task when replied to Outlook VBA and Custom Forms 2
Kelli VBA code for Outlook Using Outlook 1
S Requried a VBA Code to export Calander details to excel... Outlook VBA and Custom Forms 4
M VBA Code to extract data from an Outlook Form Using Outlook 0
M VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolde Using Outlook 0
C In need of VBA code to read / parse HTML - Outlook emails Using Outlook 0
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
R how to get Outlook VBA code to work on the current folder Using Outlook 3
J VBA code can't be completely executed in outlook 2013 Using Outlook 0
D VBA: Send-From Code for Template Shortcut? Using Outlook 0
P VBA Code being completely ignored by Outlook Using Outlook 7
M Updating VBA code from outlook 2007 to outlook 2010 Using Outlook 1
J VBA code to determine 'show' state of SearchBar Using Outlook 7
D VBA code running on Server? Shared mailbox email routing Using Outlook 3
L Send E-mail with VBA code from [E-mail Distribution Group] if I have “Send as” Using Outlook 6
S Outllok 2007 VBA code to send mail automatically from drafts folder Using Outlook 1
S ThisOutlookSession in VBA not there anymore and code is gone Using Outlook 2
F No Attachment Warning - VBA Code HELP Outlook VBA and Custom Forms 1
J VBA code (rules) won't work after reboot Outlook VBA and Custom Forms 2
N VBA code to show today's date + a sequencial number in subject lin Outlook VBA and Custom Forms 1
A Accessing .pst folder in outlook using VBA Code Outlook VBA and Custom Forms 4
C Beginner Needs VBA Help in Modifying Code Outlook VBA and Custom Forms 2

Similar threads

Back
Top