|
-
Sep 27th, 2006, 04:19 AM
#1
Thread Starter
Lively Member
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:
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
Last edited by Hack; Sep 27th, 2006 at 09:54 AM.
Reason: Added [vbcode] [/vbcode] tags for more clarity.
-
Sep 27th, 2006, 04:39 AM
#2
Re: Outlook
Did you set a reference to MS Outlook xx.0 Object Library?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 27th, 2006, 04:52 AM
#3
Thread Starter
Lively Member
Re: Outlook
Yes i set the refrence for MS Outlook 10.0
i found one more thing that if i run outlook and then run the code it works fine but without running outlook it won't run
-
Sep 27th, 2006, 09:57 AM
#4
Re: Outlook
VB Code:
'Try
Set oApp = CreateObject("Outlook.Application")
'instead of
Set oApp = New Outlook.Application
-
Sep 27th, 2006, 12:44 PM
#5
Re: Outlook
I can not see any issue with this line of code.
Set oApp = New Outlook.Application
If you were to create a new blank forject with the outlook reference and add the dimensioning line and outlook creation line it should work. If it does then either there is something else going on in your app or possibly outlook may need repair. Do you have all the latest updates for it? Did you try a Help menu > Detect and Repair?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 28th, 2006, 04:00 AM
#6
Thread Starter
Lively Member
Re: Outlook
i have changed the code to
Set oApp = CreateObject("Outlook.Application")
and also done Help menu > Detect and Repair
but Getting same error message
-
Sep 28th, 2006, 04:28 AM
#7
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|