S
Scott Fenstermacher
Hi. I'm trying to access another mailbox to which I have rights. I want to
read the subject, if it contains "New Employee", pass the body onto another
subroutine which will parse the information out for account creation. Every
time I try to access the body method, it fails. The Watch window says
<Method 'Body' of object 'MailItem' failed>. Trying to access the body
through Outlook Spy gives me the security prompt about accessing the body of
an email. When I try to set a MailItem object to the olItem variant, I get
a type mismatch error. Any ideas?
-Scott Fenstermacher
Here is my code.
===========================
Dim objNs As NameSpace
Dim objInbox As MAPIFolder
Dim olMail As Variant
Dim NS As Outlook.Recipient
Dim I As Integer
'On Error Resume Next
Set objNs = Application.GetNamespace("MAPI")
Set NS = objNs.CreateRecipient("Network Support/Help Desk")
NS.Resolve
If NS.Resolved Then
Set objInbox = objNs.GetSharedDefaultFolder(NS, olFolderInbox)
Else
MsgBox "Unable to resolve Network Support Inbox!", vbOKOnly +
vbExclamation, "Error connecting to inbox"
Exit Sub
End If
For Each olMail In objInbox.Items
If InStr(olMail.Subject, "New Employee") > 0 Then
' Dim Email as Outlook.MailItem
' Set Email = olMail
' This gives a type mismatch error!
ParseEmail (olMail.Body)
' This doesn't like the Body method...
End If
Next
Set objInbox = Nothing
Set objNs = Nothing
Set NS = Nothing
read the subject, if it contains "New Employee", pass the body onto another
subroutine which will parse the information out for account creation. Every
time I try to access the body method, it fails. The Watch window says
<Method 'Body' of object 'MailItem' failed>. Trying to access the body
through Outlook Spy gives me the security prompt about accessing the body of
an email. When I try to set a MailItem object to the olItem variant, I get
a type mismatch error. Any ideas?
-Scott Fenstermacher
Here is my code.
===========================
Dim objNs As NameSpace
Dim objInbox As MAPIFolder
Dim olMail As Variant
Dim NS As Outlook.Recipient
Dim I As Integer
'On Error Resume Next
Set objNs = Application.GetNamespace("MAPI")
Set NS = objNs.CreateRecipient("Network Support/Help Desk")
NS.Resolve
If NS.Resolved Then
Set objInbox = objNs.GetSharedDefaultFolder(NS, olFolderInbox)
Else
MsgBox "Unable to resolve Network Support Inbox!", vbOKOnly +
vbExclamation, "Error connecting to inbox"
Exit Sub
End If
For Each olMail In objInbox.Items
If InStr(olMail.Subject, "New Employee") > 0 Then
' Dim Email as Outlook.MailItem
' Set Email = olMail
' This gives a type mismatch error!
ParseEmail (olMail.Body)
' This doesn't like the Body method...
End If
Next
Set objInbox = Nothing
Set objNs = Nothing
Set NS = Nothing