Filing emails in a specific folder on C drive using VBA (Outlook 2010)-VBForums
Results 1 to 3 of 3

Thread: Filing emails in a specific folder on C drive using VBA (Outlook 2010)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    1

    Filing emails in a specific folder on C drive using VBA (Outlook 2010)

    Is there any way that you can create vba code so that if you enter a code in an input box it will use that code to search for that code within a folder name and save the email in that specific folder on your C drive.

    So, say you have the following folders on C drive:-

    C:\Email\0010-Test
    C:\Email\0020-Test 2
    C:\Email\0030-Test 3

    Is there any way the VBA code can be made to save the email in the folder "0010-Test" folder when only the 0010 bit is entered in the input box? The bit the VBA will need to search for will always be the part of the folder name before the dash.

    Thanks
    Dave

  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    22

    Re: Filing emails in a specific folder on C drive using VBA (Outlook 2010)

    I don't at the moment have time to throw any code up for you, but I would use .FindNext (http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx) and .SaveAs (http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx). So if you get to the point where you find what you're looking for, you can save the mail item where you want (ie Email_I_was_lookingfor.SaveAs "C:\Email\0010-Test.txt" OlSaveAsType.olTXT). Also: http://msdn.microsoft.com/en-us/libr.../ff868727.aspx

    Obviously if you want to run this through a whole folder you're going to have to use some loops and variables. An easy naming strategy might be to use the subject line depending on the number of replicates.

    Happy coding, if I have time will try to help more.
    Last edited by Volos; Feb 13th, 2013 at 08:34 PM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,961

    Re: Filing emails in a specific folder on C drive using VBA (Outlook 2010)

    Is there any way the VBA code can be made to save the email in the folder "0010-Test" folder when only the 0010
    you can use DIR to return a file /folder name string from wildcard

    Code:
    root = "C:\email\"
    num = inputbox("enter folder number")
    fold = dir(root & num & "*", vbdirectory)
    do while len(fold) > 0
       if getattr(root & fold) and vbdirectory then foldlist = root & fold & vbnewline
       fold = dir
    loop
    if len(foldlist) = 0 then foldlist = "none"
    msgbox  "the following folders were found that match the entered folder number" & vbnewline & foldlist
    if only 1 folder is found that matches, you can use it directly, else you have to determine which to use
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.