OfficeDev / VBA-content

All content in this repository has been migrated to a new repository (https://github.com/MicrosoftDocs/VBA-Docs). Please do not open issues or pull requests here. We are no longer monitoring this content.
https://github.com/MicrosoftDocs/VBA-Docs
Creative Commons Attribution 4.0 International
564 stars 434 forks source link

Catching events doesn't work as advertised #17

Closed Darker closed 9 years ago

Darker commented 9 years ago

I have a problem with this basic tutorial: https://github.com/OfficeDev/VBA-content/blob/master/Outlook-VBA/articles/560bb264-05d0-dbc6-39c2-b95b12f50ed9.md

Also hosted on msdn: https://msdn.microsoft.com/en-us/library/bb206733.aspx

I produced following code, placed in ThisOutlookSession:

Dim WithEvents myOlBar As Outlook.OutlookBarPane

Private Sub Application_NewMail()
    MsgBox "New mail"
End Sub
Private Sub myOlBar_BeforeNavigate(ByVal Shortcut As OutlookBarShortcut, Cancel As Boolean)
    MsgBox Shortcut.Name
End Sub

Private Sub Application_Startup()
 Set myOlBar = Application.ActiveExplorer.Panes(1)
End Sub

I enabled macros:

image description

I confirmed that I allow macros after outlook restart:

image description

Still I get no effect whatsoever. However if I put some debug code in application startup callback, it works - I can print Hello world on startup:

Private Sub Application_Startup()
   MsgBox "Hello world!"
End Sub

image description

So why is startup the only callback that works?

chbighammsft commented 9 years ago

Thanks for your comment. You can use GitHub to make changes and additions to the VBA documentation, but for issues with your code we suggest that you post your question on one of these forums.

https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev http://stackoverflow.com/questions/tagged/outlook