This the small code whcih checks for new email in outlook and display a message but whenever i run this app i get msg that "can't create object" althoug i have outlook installed
plz helpVB Code:
Sub ReadEmail() Dim oApp As Outlook.Application Dim oNameSpace As NameSpace Dim oFolder As MAPIFolder Dim oMailItem As Object Dim cFolder As MAPIFolder Dim myItems As Items Dim MailCounter As Integer, FolderCount As Integer MailCounter = 0 Dim sMessage As String Set oApp = New Outlook.Application '<<<<<<<<<<<<------------------Error Set oNameSpace = oApp.GetNamespace("MAPI") Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox) MailCounter = oFolder.UnReadItemCount For FolderCount = 1 To oFolder.Folders.Count Set cFolder = oFolder.Folders(FolderCount) For Each oMailItem In cFolder.Items If oMailItem.UnRead = True Then List1.AddItem oMailItem.ReceivedTime End If Next oMailItem MailCounter = mailcount + cFolder.UnReadItemCount Next Set oMailItem = Nothing Set oFolder = Nothing Set mFolder = Nothing Set oNameSpace = Nothing Set oApp = Nothing msg: If MailCounter = 1 Then MsgBox "You have 1 new message" Else MsgBox "You have " & MailCounter & " new messages" End If End Sub




Reply With Quote