Results 1 to 40 of 55

Thread: [RESOLVED] moving mail from sub folder to personal folder

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    49

    Resolved [RESOLVED] moving mail from sub folder to personal folder

    Hi there, I am a complete novice to coding and have been trying to construct a piece of code from other bits i have got for Outlook 2000

    I have a rule that moves specific new mail from the inbox to a subfolder and a macro extracts the attachment. This all works great, but now is where the new code comes in! I need the mail in the sub folder to then be moved to a personal folder. As far as i can see rules don't work on subfolders and i've been playing with code and realised i need to declare my own function to get to the personal folder.

    Here is what i have, i can not work out how to adapt the getfolder function to my needs. running as it is i get errors. I'm at that point where i feel like throwing in the towel, i just can't get my head around it! its probably really simple!

    VB Code:
    1. Public Function GetFolder(strFolderPath As String) As MAPIFolder
    2.   ' folder path needs to be something like
    3.   '   "Public Folders\All Public Folders\Company\Sales"
    4.   Dim objApp As Outlook.Application
    5.   Dim objNS As Outlook.NameSpace
    6.   Dim colFolders As Outlook.Folders
    7.   Dim objFolder As Outlook.MAPIFolder
    8.   Dim arrFolders() As String
    9.   Dim I As Long
    10.   On Error Resume Next
    11.  
    12.   strFolderPath = Replace(strFolderPath, "/", "\")
    13.   arrFolders() = Split(strFolderPath, "\")
    14.   Set objApp = CreateObject("Outlook.Application")
    15.   Set objNS = objApp.GetNamespace("MAPI")
    16.   Set objFolder = objNS.Folders.Item(arrFolders(0))
    17.   If Not objFolder Is Nothing Then
    18.     For I = 1 To UBound(arrFolders)
    19.       Set colFolders = objFolder.Folders
    20.       Set objFolder = Nothing
    21.       Set objFolder = colFolders.Item(arrFolders(I))
    22.       If objFolder Is Nothing Then
    23.         Exit For
    24.       End If
    25.     Next
    26.   End If
    27.  
    28.   Set GetFolder = objFolder
    29.   Set colFolders = Nothing
    30.   Set objNS = Nothing
    31.   Set objApp = Nothing
    32. End Function
    33.  
    34. Sub MoveItems()
    35.  
    36. Dim myolAPP As New Outlook.Application
    37. Dim myNameSpace As Outlook.NameSpace
    38. Dim myInbox As Outlook.MAPIFolder
    39. Dim myInputFolder As Outlook.MAPIFolder
    40. Dim myDestFolder As Outlook.MAPIFolder
    41. Dim myItems As Outlook.Items
    42. Set myNameSpace = myolAPP.GetNamespace("MAPI")
    43. Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
    44. Set myInputFolder = myInbox.Folders("test1")
    45. Set myDestFolder = GetFolder("Personal Folders\test2")
    46. Set myItems = myInputFolder.Items
    47. myItems.Move myDestFolder
    48.  
    49. End Sub

    Many thanks for any help.
    Last edited by fox 2; Dec 21st, 2005 at 08:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width