Smarter NameSpace Reference...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the following code in a VB.Net 2005 add-in for Outlook 2003 and on
50% of my workstations I get a Cast Object error. So obviously my approach is
wrong:

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
....
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Dim objNS As Outlook._NameSpace = objOutlook.Session
objFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
objFolderItems = objFolder.Items
AddHandler objFolderItems.ItemAdd, AddressOf objFolderItemAdded
....
End Sub

So I believe it's wrong to create a new Outlook session from within Outlook.
How else would I do it to avoid the cast error?

DG
 
Back
Top