Automation Error

Sandgroper48

New Member
OS Version(s)
  1. Windows
Outlook version
Outlook 2019 64-bit
Email Account
IMAP
Operating system::    Windows 10Pro
Outlook version:     2019
Email type or host:    IMAP

Would appreciate any guidance on the following problem:

I have a macro to run all my Rules in Outlook 2019 (desktop Ver. 2408 Build 17928.20114) but it keeps going into error at
For Each rule in myRules
code in here ..............
NEXT

It goes into error at "Next" with an error message of "Automation error" -2146664191(800c8101) For loop not inialized"

I know the whole of the code is correct because it runs perfectly on my wife's PC with no errors. For that reason I haven't posted the whole code here because I that it runs without error on another PC. Both PC's are running Outlook 2019 (Ver. 2408 Build 17928.20114) under Windows 10Pro.

The error on my PC seems relate to any call to Next or Loop or iterative code such as For Each, For, with Next or Do While, Do Until with Loop because even a very simple procedure such as below also throws the same error at NEXT:

Sub Error_Test()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim i As Integer

' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules
i = myRules.count
' iterate all the rules
For Each rl In myRules
Debug.Print rl
Next error throws Here!
End Sub​

Again, this very simple code works perfectly on the other PC.

I have exhausted just about every possible solution I can find on the Internet with no actual solution found. I have also completely removed and re-installed Outlook 2019 (classic on my PC wih no change to the issue.
Now at the hair pulling stage!
Any assistance would be most welcome.
 
Hmmm. it works here. Did you delete the Here line and retype it? I've had errors copying code - it seems a character is hidden at the end of the line that triggers the error.

How did you move it from the other computer? Pasting into an email can add the hidden characters but by text file or exported .bas should not cause problems.
 
Hmmm. it works here. Did you delete the Here line and retype it? I've had errors copying code - it seems a character is hidden at the end of the line that triggers the error.

How did you move it from the other computer? Pasting into an email can add the hidden characters but by text file or exported .bas should not cause problems.
Diane thanks for the response. I moved the code from my PC to my wife's using Export>Module as a .bas file then imported into Wife's PC as the same file. All code in the Module runs perfectly on my Wife's PC but only the Sub MoveTrash() will run on my PC because that code does not involve any calls to a Loop or Next. For your review I have attached the bas file here as a Txt because the site won't accept aa a .bas file.
Strangely, I have many Excel macros involving For or Do Loops on my PC and they all run without issue so the "Automation Error" seems to be confined to Outlook. That is the reason that I took the drastic step of uninstalling and re-installing Outlook on my PC but it hasn't fixed the problem.
Thanks again for your response.
 

Attachments

That works here too. Did you try renaming the OTM file and making a new one? It's at %appdata%\microsoft\outlook. close outlook, rename it then reopen outlook.

Actually, rather than import the bas, open the text file you uploaded - copy and paste the macro from it into the VBA editor.
 
Thanks again for your reply.
I have tried:-
- deleting OTM file totally them importing .bas file from Wife's PC - no change
- deleting OTM file again then copy and paste from the .txt file that I sent to you - no change
- deleting OTM file again then copied entire OTM file from Wife's PC to mine - no change
Comparing libarary references (Tools>References) bewteen the two PC's; they are exactly the same and comprise:
(1) Visual Basic for Applications
(2) Microsoft Outlook 16.0 Object Library
(3) OLE Automation
(4) Microsoft Office 16.0 Object Library
The only difference that I note between the two PC's is that my Wife's vb visual basic pane has the tree as:
- Project1(vbaProject.OTM)
- Microsoft Outlook Objects
- ThisOutllookSession
- Modules
- Module1
On my PC the "Microsoft Outlook Objects" is missing from the tree (no sure why that would be missing).

Also I have noted that my Outlook version is 64 bit whereas my Wife's PC has 32 bit version. Mine must have got the 64 bit version from my recent uninstall and reinstall whilst trying to fix this issue.
Baffled!
 
64-bit is the default install - you need to select the 32 bit version if you need it to support older addins. I'm using 64 bit so its not that... and there is nothing in it that would use another object model, so the references are ok.

For the VB tree - it looks like this? Click the manilla folder icon above 'project1' to toggle the folders between the two views.
1725506560385.png



1725506665418.png
 
64-bit is the default install - you need to select the 32 bit version if you need it to support older addins. I'm using 64 bit so its not that... and there is nothing in it that would use another object model, so the references are ok.

For the VB tree - it looks like this? Click the manilla folder icon above 'project1' to toggle the folders between the two views.
View attachment 4270


View attachment 4271
Yes - my dumb! So mine does include the "Microsoft Outlook Objects". Thanks,
 
Yes - my dumb! So mine does include the "Microsoft Outlook Objects". Thanks,
I won't tell you how long it took me to figure out how to get the folder version after deleting the VBA registry key. :)
 
SOLVED - Finally, I think I have found a solution to my baffling problem. After countless hours of problem solving I decided to create a new email Profile them added the VBA code to the new profile and the problematic macro now runs to the end without falling over at the "NEXT" line of code. I have tested it against two (2) manually created Rules and it runs without errors but haven't yet imported all my Rules (22) for a complete test. However, if it falls over once the old Rules are imported then at least I will know what is causing the error.
This issue can now be tagged as Solved - many thanks to those that responded with suggested fixes.
 
Further to last message. After importing my 22 x Rules the "Automation error" has returned. Deleting all imported Rules returns the code to a working state. Must be some unknown bug in one of my rules!
So now to start the process of re-creating all my Rules manually!
 
I'm wondering if one rule is corrupt and causing it to error...

I don't think adding error handling will help since it does before it starts. Delete some of the rules or delete all and manually create a couple of rules and see if it works. (The account I tested it on has 5 rules.)
 
Yes thanks - Diane. See my prevoius post - I am currently in the labourius task of re-creating all 22 Rules manually as I am unsure of how I could identify the "culprit" rule.
 
Similar threads
Thread starter Title Forum Replies Date
B Automation error running VB macro code Outlook VBA and Custom Forms 8
X Outlook automation pull from PDF Using Outlook 5
M Subject Line Automation - Trigger Script Delayed Outlook VBA and Custom Forms 2
T Outlook Prf/Automation question Using Outlook 2
J Message automation: message size growth Outlook VBA and Custom Forms 2
D Outlook2007 Email problem with automation Outlook VBA and Custom Forms 4
J Security Restriction Seriously Hampers Outlook Automation Outlook VBA and Custom Forms 1
X Access Outlook Contact Groups with Automation? Outlook VBA and Custom Forms 3
J Adding a background image to a mail item using automation Outlook VBA and Custom Forms 2
G Error - "Customized functionality in this application will not work because the certificate" Outlook VBA and Custom Forms 1
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
G Outlook 365 My iCloud Outlook doesn’t work after reinstalling Microsoft365 on Windows 10 PC – now I get error message on contacts and calendar Using Outlook 1
V Outlook Error The Attempted operation Failed. An Object Could Not be found Outlook VBA and Custom Forms 0
S macro error 4605 Outlook VBA and Custom Forms 0
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
D.Moore Strange VBA error Outlook VBA and Custom Forms 4
T Event Error on non existent Event. Using Outlook 2
P now on office 365 but getting error messages about missing Outlook 2013 cache folders Using Outlook 2
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
A Links in email getting error message about group policy Using Outlook 4
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
Cathy Rhone Mail merge error message Using Outlook 1
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
V Outlook error 500 Using Outlook 2
O Comma Separated Values.ADR and A file error has occurred in the translator Using Outlook 6
D We're sorry but outlook has run into an error Using Outlook 6
D Outlook 2016 Outlook Error Msg "The operation cannot be performed ..." How to Stop it Using Outlook 4
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
H Outlook 2019 Certificate error Using Outlook 2
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
E Complite error on SaveAsFile method Outlook VBA and Custom Forms 2
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
M Compile error: User-defined type not defined Outlook VBA and Custom Forms 0
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
M ERROR: None of your email accounts could send to this recipient Using Outlook 2
J OLADD.FAE Error When Exporting Contacts Using Outlook 6
C Send/receive error 80040119 Using Outlook 2
W error with the permission for the file Outlook VBA and Custom Forms 0
L Outlook 2019 MAC sync error after working for 4 hours Using Outlook 1
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
M error code 0x8DE00006 Using Outlook 1
M Desktop Version Of Outlook Generating Error Using Outlook 4
M Send/Receive error 0x800CCC0F Using Outlook 0
T Outlook 2016 CSV Translator Import Error Using Outlook 6
ManaarZakaria I'm afraid of this issue, cause of strange error Exchange Server Administration 2
P Suppress dialog box on email check error? Using Outlook 5
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5

Similar threads

Back
Top