Outlook Does Not Always Load Macros (or run Application_Startup()) on Startup

A

ajkessel

Reposting from microsoft.public.outlook.vba, where I received no
response:

Sometimes when I start Outlook 2003, I get a message warning me about
macro security, and I select "Enable Macros," and everything works as
expected. Sometimes, however, there is no such message, and
Application_Startup() is not executed, and my event-triggered
subroutines (e.g., sentItems_ItemAdd) are not run. If I go to the VBA
and run Application_Startup() manually, everything works again.

I have not been able to find any consistency between the instances
where it works from startup vs. the times where I have to manually go
into VBA to enable the subroutines. It does not seem to matter whether
it is the first time I've started Outlook between reboots or a later
time; or what else is running; etc..

Any ideas? Has anyone else experienced anything similar?
 
K

Ken Slovak - [MVP - Outlook]

What code is in Application_Startup? Is it possible it might be throwing
intermittent errors? If that's the case that would explain the problem.
 
A

ajkessel

No errors are visible, anyway. The code is very simple:

Private Sub Application_Startup()
Dim ns As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Set ns = Application.GetNamespace("MAPI")
Set fld = ns.GetDefaultFolder(olFolderSentMail)
Set sentItems = fld.Items
Set fld = Nothing
Set ns = Nothing
End Sub

My understanding is that it just chooses not to run any macros at all
on startup sometimes but it does on others. I can tell that the macros
are being run on startup because I get the security warning/"enable
macros" dialog. Whenever I get that dialog, the macros work as
expected. About 60-70% of the time, I don't get that dialog, and I have
to manually go and run application_startup() from the VBA window. In
fact, as soon as I open the VBA window, I get the dialog, so presumably
it is checking macros for the first time then.
 
K

Ken Slovak - [MVP - Outlook]

It looks OK. We put in an inquiry about this to MS but we haven't heard
anything back yet.

About all I can think of offhand is maybe some corruption of the VBA project
file. It's called VBAProject.OTM in the file system, find it and delete it
or rename it to something like VBAProject.OTM.OLD when Outlook isn't
running. When you start Outlook a new one will be created.

Make sure you are showing hidden files and folders in Windows Explorer
before looking for that file.

You can copy existing code to Notepad or export the code modules before you
rename/delete the project file so can later paste your existing code back
into the new project or import the exported modules. See if that helps.
 
Joined
Apr 24, 2023
Messages
1
Reaction score
0
Microsoft is pitiful when you see that this random firing Application_Startup() issue still exists in all Outlook versions after more than 20 years...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top