Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Operation Failed' for Microsoft Outlook

Status
Not open for further replies.

richardii

Programmer
Jan 8, 2001
104
GB
I was experimenting to write my own email detector - if Outlook is not open when you run this script then the first time it runs you get the message 'Operation Failed' - the second time it works. Works ok if Outlook is open. Does anyone know why? Thanks!

Dim objOL
Dim objNS
Dim objFolder
Dim objAllItems
Dim objItem
Dim nCount, nItems
Dim strCriteria
'nItems is the total items in Inbox
nItems = 0
'nCount is the unread ones
nCount = 0
Dim lAnswer

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNameSpace("MAPI")
Set objFolder = objNS.GetDefaultFolder(6)
Set objAllItems = objFolder.Items

nItems = objFolder.Items.Count

strCriteria = "[UnRead] = True"
Set objAllItems = objFolder.Items.Restrict(strCriteria)
For Each objItem In objAllItems
nCount=nCount+1
Next

lAnswer = MsgBox ("Mail(s) in your Inbox = " & nItems & vbCr & "Unread mails = "& nCount & vbCr & "Read your email now?", vbYesNo + vbQuestion + vbDefaultButton1, Date() & " "& Time())
If lAnswer = vbYes then
Set objOL=CreateObject("WScript.Shell")
objOL.Run "outlook.exe"
End if



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top