Hi,
I've been looking all around the web for some examples of using
VB with Outlook, and I've found something strange. There seems to be two common ways of doing what looks like the same thing:
Method 1
Public Sub Application_Startup()
' initialization code
End Sub
Private Sub Application_NewMail()
' code to run when new mail arrives, using Application object
End Sub
Method 2
Dim WithEvents myOlApp As Outlook.Application
Public Sub Application_Startup()
Set myOlApp = CreateObject("Outlook.application")
' initialization code
End Sub
Private Sub myOlApp_NewMail()
' code to run when new mail arrives, using myOlApp object
End Sub
Can someone please tell me what the difference is between these two chunks of code and what reasons there are to prefer one over the other? (If it matters, I'm using Outlook 2000.) Thanks!
-E.D.