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
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.
Re: Filing emails in a specific folder on C drive using VBA (Outlook 2010)
Quote:
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