Frank Helk
asked on
Outlook 2012 VBA: Object missing
Hello, friends ...
Here's a strange problem ... I have Outlook 2010 and I want to run some rules upon i.e. by clicking a button. There's a lot of samples on the web, and they follow the same scheme. Unfortunately, when I try 'em, I run into a problem ... here's some typical sample:
When I try that code, set into a new module as recommended, it stops with an error in the line
and grumbles that it can't find the property DefaultStore.
I'm not that bad in VBA and debugging it, but that thing puzzles me completely ... any hint ?
Here's a strange problem ... I have Outlook 2010 and I want to run some rules upon i.e. by clicking a button. There's a lot of samples on the web, and they follow the same scheme. Unfortunately, when I try 'em, I run into a problem ... here's some typical sample:
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next’ get default store (where rules live)
Set st = Application.Session.DefaultStore
'get rules
Set myRules = st.GetRules
' iterate all the rules
For Each rl In myRules
' determine if it’s an Inbox rule
If rl.RuleType = olRuleReceive Then
' if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
When I try that code, set into a new module as recommended, it stops with an error in the line
Set st = Application.Session.Defaul tStore
and grumbles that it can't find the property DefaultStore.
I'm not that bad in VBA and debugging it, but that thing puzzles me completely ... any hint ?
Hi,
pls try
pls try
Dim ns As Outlook.NameSpace
Set ns = Application.GetNamespace("MAPI")
Set st = Ns.DefaultStore
Regards
ASKER
line 3 what's in?
Any chance to test the VBA on a different system or on an account with only one mailbox? I tested it here with Win 7/Outlook 2010 and it runs fine, no error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Rgonzo:
Line 3 of your test code in comment #41984867:
Code in comment #41984893:
in line 3 of your test code,
@Michael Pfister:
Win7/OL2010 here, too. I believe that it works on other systems, at least because that way is documented that often.
I've tried that on the system of a coworker, and there's the same behaviour.
BTW: Interestingly, in Application.Session.Stores I could read .Count with a value of 17, but the .Items collection is missing.
Line 3 of your test code in comment #41984867:
Set st = Ns.DefaultStore
Code in comment #41984893:
in line 3 of your test code,
For Each oStore In colStores
@Michael Pfister:
Win7/OL2010 here, too. I believe that it works on other systems, at least because that way is documented that often.
I've tried that on the system of a coworker, and there's the same behaviour.
BTW: Interestingly, in Application.Session.Stores
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to add the proper objects in your VBA window.
Open the VBA Window and go to Tool --> References
The reference window pops up, so ensure you have the proper references selected
You can also try to have a sub that enumerate stores. Does this work?
Open the VBA Window and go to Tool --> References
The reference window pops up, so ensure you have the proper references selected
You can also try to have a sub that enumerate stores. Does this work?
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
ASKER
@Michael Pfister:
The coworker basically has the same setup, afaik w/o the extra local storage accounts but with the Communigate MAPI connector that supplies the main account (users mailbox) and the extra accounts (projects, etc.). Just a single mailbox would imply to set up a complete new system (or at least a VM) for that - or to throw my entire setup over board. I'd prefer to circumvent that by now ;-S
Without the Communigate MAPI Connector I'd have no access to any mail server due to firewall restritions and policies (as long as I don't set up a new mail server somehere, which would have to be Exchange, btw. ... I'd prefer to circumvent that test, too ... ;-)
@xtermie:
In the meanwhile I came across that idea, too ... but I couldn't find any interestig reference that's not added already:
About the test code you've suggested:
Rgonzo proposed similar code in his comment #41984893, the result is shown in my comment #41985008 ...
The coworker basically has the same setup, afaik w/o the extra local storage accounts but with the Communigate MAPI connector that supplies the main account (users mailbox) and the extra accounts (projects, etc.). Just a single mailbox would imply to set up a complete new system (or at least a VM) for that - or to throw my entire setup over board. I'd prefer to circumvent that by now ;-S
Without the Communigate MAPI Connector I'd have no access to any mail server due to firewall restritions and policies (as long as I don't set up a new mail server somehere, which would have to be Exchange, btw. ... I'd prefer to circumvent that test, too ... ;-)
@xtermie:
In the meanwhile I came across that idea, too ... but I couldn't find any interestig reference that's not added already:
About the test code you've suggested:
Rgonzo proposed similar code in his comment #41984893, the result is shown in my comment #41985008 ...
Just create a fresh local user on your system and give it a simple mail setup, i.e. POP3 or IMAP profile. Doesn't have to work.
Then check if the VBA will enumerate the stores.
IMHO there are 2 possible causes for this:
1) the Office or just the Outlook installation is damaged
2) Communigate MAPI connector interferes with the API
Best do this on a test system:
#1 Try to perform a repair installation of your Office, then recheck
#2 Uninstall Communigate MAPI connector, then recheck
Then check if the VBA will enumerate the stores.
IMHO there are 2 possible causes for this:
1) the Office or just the Outlook installation is damaged
2) Communigate MAPI connector interferes with the API
Best do this on a test system:
#1 Try to perform a repair installation of your Office, then recheck
#2 Uninstall Communigate MAPI connector, then recheck
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks pals ...
@xtermie: Sure - the application is open and everything is already loaded.
I've tried that with an extra account, and besides of now seeing Application.Session.Stores .Count with 18 (before: 17), nothing changed.
My coworker has some simple setup (Communigate only), so I bet my problem is collateral damage by the Communigate Connector. Therefore you've been pointing into the right direction.
Thanks.
@xtermie: Sure - the application is open and everything is already loaded.
I've tried that with an extra account, and besides of now seeing Application.Session.Stores
My coworker has some simple setup (Communigate only), so I bet my problem is collateral damage by the Communigate Connector. Therefore you've been pointing into the right direction.
Thanks.
- Whats the exact VBA error message?
- How many mail accounts are configured and whats the default account?