Run a Scipt - Move to folder - Got stuck

R

RosH

Hi all,

I am trying to classify my mails into folders automatically when it
arrives, I have used the run a script rule to achieve it. Whenever a
message arrives, I want the following to happen.

1) Make a folder with the name same as the subject within the personal
folder and not as subfolder in inbox

2) Move the mail to the new folder

With the help of my friends on this group, I was able to make up the
following code which unfortunately does not do the second part. Can
somone help me to kick the macro on the back.

I have tried the following

olMail.Move myFolder.Parent.myDestFolder
olMail.Move myDestFolder
olMail.Move Parent.myDestFolder


------------------------------------------------------------------------------
Sub AutomatingClassification(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
'Dim myFolder As Outlook.Folders
'Dim myDestFolder As Outlook.Folders


strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' MsgBox olMail.Subject

Set myFolder = olNS.GetDefaultFolder(olFolderInbox)
FolderName1 = olMail.Subject

On Error Resume Next
Set myDestFolder = myFolder.Folders(FolderName1)
If myDestFolder Is Nothing Then
Set myNewFolder = myFolder.Parent.Folders.Add(FolderName1)
End If
olMail.Move myFolder.Parent.myDestFolder


Set olMail = Nothing
Set olNS = Nothing

End Sub
--------------------------------------------------------------------------------------
 
M

Michael Bauer

Am 31 Jul 2006 23:00:58 -0700 schrieb RosH:

olMail.Move myDestFolder should work.

If you create that folder then you should use the same variable or call

olMail.Move myNewFolder


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Hi all,

I am trying to classify my mails into folders automatically when it
arrives, I have used the run a script rule to achieve it. Whenever a
message arrives, I want the following to happen.

1) Make a folder with the name same as the subject within the personal
folder and not as subfolder in inbox

2) Move the mail to the new folder

With the help of my friends on this group, I was able to make up the
following code which unfortunately does not do the second part. Can
somone help me to kick the macro on the back.

I have tried the following

olMail.Move myFolder.Parent.myDestFolder
olMail.Move myDestFolder
olMail.Move Parent.myDestFolder


------------------------------------------------------------------------------
Sub AutomatingClassification(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
'Dim myFolder As Outlook.Folders
'Dim myDestFolder As Outlook.Folders


strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' MsgBox olMail.Subject

Set myFolder = olNS.GetDefaultFolder(olFolderInbox)
FolderName1 = olMail.Subject

On Error Resume Next
Set myDestFolder = myFolder.Folders(FolderName1)
If myDestFolder Is Nothing Then
Set myNewFolder = myFolder.Parent.Folders.Add(FolderName1)
End If
olMail.Move myFolder.Parent.myDestFolder


Set olMail = Nothing
Set olNS = Nothing

End Sub
--------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top