Results 1 to 7 of 7

Thread: Outlook

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Outlook

    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 help
    VB Code:
    1. Sub ReadEmail()
    2.     Dim oApp As Outlook.Application
    3.     Dim oNameSpace As NameSpace
    4.     Dim oFolder As MAPIFolder
    5.     Dim oMailItem As Object
    6.     Dim cFolder As MAPIFolder
    7.     Dim myItems As Items
    8.     Dim MailCounter As Integer, FolderCount As Integer
    9.     MailCounter = 0
    10.     Dim sMessage As String
    11.     Set oApp = New Outlook.Application          '<<<<<<<<<<<<------------------Error
    12.     Set oNameSpace = oApp.GetNamespace("MAPI")
    13.     Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
    14.     MailCounter = oFolder.UnReadItemCount
    15.    
    16.     For FolderCount = 1 To oFolder.Folders.Count
    17.     Set cFolder = oFolder.Folders(FolderCount)
    18.     For Each oMailItem In cFolder.Items
    19.     If oMailItem.UnRead = True Then
    20.     List1.AddItem oMailItem.ReceivedTime
    21.     End If
    22.     Next oMailItem
    23.     MailCounter = mailcount + cFolder.UnReadItemCount
    24.     Next
    25.     Set oMailItem = Nothing
    26.     Set oFolder = Nothing
    27.     Set mFolder = Nothing
    28.     Set oNameSpace = Nothing
    29.     Set oApp = Nothing
    30. msg:
    31.     If MailCounter = 1 Then
    32.     MsgBox "You have 1 new message"
    33.     Else
    34.     MsgBox "You have " & MailCounter & " new messages"
    35.     End If
    36.     End Sub
    Last edited by Hack; Sep 27th, 2006 at 09:54 AM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width