Class method failed.... 
Author Message
 Class method failed....

Hello,

I want to copy new emails into a personal folder, and
I want to use VBA rather than the Rules Wizard. My code
follows, and I am NEW to VBA in Outlook.  

When I get a new mail it tells me that the

   Method 'Class' of object 'MailItem' failed
   error code of -2147221233

TIA,
Per

Option Explicit

Private WithEvents olInboxItems As Outlook.Items

Private Sub Application_Startup()
    Dim objNS As NameSpace
    Set objNS = Application.GetNamespace("MAPI")
    Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
    Set objNS = Nothing
End Sub

Private Sub Application_Quit()
    Set olInboxItems = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
    Dim objNS As NameSpace
    Dim objInbox As MAPIFolder
    Dim objArcFolder As MAPIFolder
    Dim objCopiedItem As MailItem

    If Item.Class = olMail Then  ' <---- *****  HERE IS THE PROBLEM *****
    Set objNS = Application.GetNamespace("MAPI")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set objArcFolder = objNS.Folders("Personal Folders").Folders("MAILArchive")

    Set objCopiedItem = Item.Copy
    objCopiedItem.Move objArcFolder

    End If

    Set objCopiedItem = Nothing
    Set objArcFolder = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing
End Sub



Sun, 03 Oct 2004 04:50:37 GMT  
 Class method failed....
Hi,

I don't use VB, but am programming using Progress and com-
handles. I don't have a solution for you, but it appears
to be a problem with outlook 97. It doesn't have any
reference to the 'Class'. I was sent example code
containing 'Class' which worked fine on the sender's pc -
Outlook 2000 - but won't run on mine. Maybe you could look
into this possibility?

Kind Regards,

Emma.

Quote:
>-----Original Message-----
>Hello,

>I want to copy new emails into a personal folder, and
>I want to use VBA rather than the Rules Wizard. My code
>follows, and I am NEW to VBA in Outlook.  

>When I get a new mail it tells me that the

>   Method 'Class' of object 'MailItem' failed
>   error code of -2147221233

>TIA,
>Per

>Option Explicit

>Private WithEvents olInboxItems As Outlook.Items

>Private Sub Application_Startup()
>    Dim objNS As NameSpace
>    Set objNS = Application.GetNamespace("MAPI")
>    Set olInboxItems = objNS.GetDefaultFolder

(olFolderInbox).Items

- Show quoted text -

Quote:
>    Set objNS = Nothing
>End Sub

>Private Sub Application_Quit()
>    Set olInboxItems = Nothing
>End Sub

>Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
>    Dim objNS As NameSpace
>    Dim objInbox As MAPIFolder
>    Dim objArcFolder As MAPIFolder
>    Dim objCopiedItem As MailItem

>    If Item.Class = olMail Then  ' <---- *****  HERE IS
THE PROBLEM *****
>    Set objNS = Application.GetNamespace("MAPI")
>    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
>    Set objArcFolder = objNS.Folders("Personal

Folders").Folders("MAILArchive")

- Show quoted text -

Quote:

>    Set objCopiedItem = Item.Copy
>    objCopiedItem.Move objArcFolder

>    End If

>    Set objCopiedItem = Nothing
>    Set objArcFolder = Nothing
>    Set objInbox = Nothing
>    Set objNS = Nothing
>End Sub
>.



Sun, 03 Oct 2004 16:50:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Active Method of Range Class failed

2. select method of range class failed ?

3. Public Method in a class calling a private method in same class yields ByRef error

4. followhyperlink method fails to use method constant other than msoMethodGet

5. Remove Interface Methods from class methods

6. How to call one VB class module method from another class in an ActiveX dll

7. Using a UDT in a Class method, how to make a class module public

8. Classes - Using Classes as method arguments???

9. Excel VBA Q: Error 1004 Method method of Object class failed?

10. Open Method of RecordSet fails when changing Regional Settings

11. Working append qry fails when invoked with Execute method

12. SOS: method showSave ICommonDialog failed

 

 
Powered by phpBB® Forum Software