Outlook VBA Error

  • Thread starter Thread starter IT
  • Start date Start date
I

IT

I have copy the code to our outlook VBA editor, after enable the macro show
error with this field, please advice how to correct this problems.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim objNS As NameSpace

Dim objFolder As MAPIFolder

Set objNS = Application.GetNamespace("MAPI")

Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" And _
IsInDefaultStore(objFolder) Then

Set Item.SaveSentMessageFolder = objFolder

End If

Set objFolder = Nothing

Set objNS = Nothing

End Sub



Public Function IsInDefaultStore(objOL As Object) As Boolean

Dim objApp As Outlook.Application

Dim objNS As Outlook.NameSpace

Dim objInbox As Outlook.MAPIFolder

On Error Resume Next

Set objApp = CreateObject("Outlook.Application")

Set objNS = objApp.GetNamespace("MAPI")

Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

Select Case objOL.Class

Case olFolder

If objOL.StoreID = objInbox.StoreID Then

IsInDefaultStore = True

End If

Case olAppointment, olContact, olDistributionList, _

olJournal, olMail, olNote, olPost, olTask

If objOL.Parent.StoreID = objInbox.StoreID Then

IsInDefaultStore = True

End If

Case Else
MsgBox "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" items and will return False.", _
, "IsInDefaultStore"

End Select

Set objApp = Nothing

Set objNS = Nothing

Set objInbox = Nothing

End Function



Thanks

Jackie Wong
 
Try removing the blank lines between statements.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I have apply this code to Outlook Code it delected the error with this
statment. I have try remobe the blank link , but does not work.


Set Item.SaveSentMessageFolder = objFolder

End If
and
Case olAppointment, olContact, olDistributionList, _
and
MsgBox "This function isn't designed to work " & _

Thanks
Jackie Wong
 
Please be specific: what doesn't work? Show the code, as editing, and point
out any statement that generates a design-time or runtime error.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Dear
The error statment as below.

If TypeName(objFolder) <> "Nothing" And _
IsInDefaultStore(objFolder) Then
- complile error / Syntax error

Case olAppointment, olContact, olDistributionList, _
- complile error / Syntax error

MsgBox "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" items and will return False.", _
, "IsInDefaultStore"
- complile error / Syntax error

Thanks
jackie
 
1) A better way to check whether an object variable has a reference to an
actual object is to check for obj Is Nothing. Also, try breaking statements
into pieces so that you perform one operation at a time. That will make it
easier to locate any problems:

Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
If IsInDefaultStore(objFolder) Then
Set Item.SaveSentMessageFolder = objFolder
End If
End If

2) Did you try changing:

Case olAppointment, olContact, olDistributionList, _

olJournal, olMail, olNote, olPost, olTask

to

Case olAppointment, olContact, olDistributionList, _
olJournal, olMail, olNote, olPost, olTask

or

Case olAppointment, olContact, olDistributionList, olJournal, olMail,
olNote, olPost, olTask

3) For a complicated MsgBox statement, try creating the message text
separately:

strMsg = "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" items and will return False."
MsgBox strMsg, ,"IsInDefaultStore"
 
Back
Top