I have searched the internet for a solution to VBA not working consistently in Windows 7 64 bit systems.
It was an OS problem, but affected all my Outlook VB code, as well as other ActiveX code.
Here is what I did to fix the problem.
Windows 7 has a service called ActiveX Installer (AxInstSV), which is described to provide UAC validation for the installation of ActiveX controls. I set this service to startup type "Automatic" in Control Panel: Administrative Tools: Services, and then rebooted.
All is now well and all my VB code works again, including my Outlook code.
Writing VBA code for Microsoft Outlook
Visual Basic for Applications (VBA) is one of two programming languages available for writing code in Outlook. (The other is VBScript, which is used by Microsoft Outlook custom forms. You can also automate Outlook using VBA in other Outlook applications. Even developers who program in other languages, such as VB.NET and C# from Visual Studio, will find Outlook VBA useful for exploring Outlook’s capabilities and prototyping. Among the useful procedures that you can write with Outlook VBA are:
- Macros to run code on demand by pressing Alt+F8 or by adding the macro as a custom toolbar button
- "Run a script" rule procedures that can be used to process incoming messages and meeting requests
- Event handlers to respond to the user’s interaction with Outlook or with such events as Reminders.ReminderFire
Getting started with Outlook VBA
To launch VBA in Outlook, press Alt+F11. Macro security is set to High by default, which means that unsigned projects will not run. You can change macro security with the Tools | Macro | Security command. Also, you can use the Selfcert.exe program that comes with Office to generate a local security certificate for signing the project. For more pointers on getting started with Outlook VBA, see:
The key to using VBA with Outlook is understanding the Outlook Object Model, which defines what objects, properties, methods, and events are available to your code. The object model is the same for every language. Therefore, the information here on Outlook techniques can be applied to any code environment that uses Outlook objects.
Any code that you create in the Outlook VBA environment is stored in a file named VBAProject.otm. The location of this file depends on your exact Windows setup; see Outlook & Exchange/Windows Messaging Backup and Dual-Boot.
When you first open Outlook VBA, it will already have a built-in class module named ThisOutlookSession which supports an intrinsic Application object and its events. In addition to backing up the VBAProject.otm file, you might also want periodically to export the individual modules from the project and back them up, too.
You can copy the VBAProject.otm file to another user’s machine but the macros won’t run until the user has actually used one of the Tools | Macro commands. See Distributing Microsoft Outlook VBA Code for other thoughts and techniques on distributing VBA macros. Even though you can copy the VBAProject.otm file, it’s still not a supported method for distributing Outlook macros company-wide. A better method is to create an Outlook add-in.
- Making Microsoft Outlook Useful – quick introduction to working with folders and messages
- Using VBA in Outlook