Move E-Mails to Another Folder

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I receive many emails in a certain way, and would like to select them and move them to another subfolder under Inbox.....so here is a code I found and I have a folder named "Family" under Inbox, but when I run the code after selecting the email, it says the folder doesn't exist.....so what to change please?

Sub MoveSelectedMessagesToFolder()

On Error Resume Next

Dim objFolder As outlook.MAPIFolder, objInbox As outlook.MAPIFolder

Dim objNS As outlook.NameSpace, objItem As outlook.mailItem

Set objNS = Application.GetNamespace(“MAPI”)

Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

Set objFolder = objInbox.Folders("Family")

'Assume this is a mail folder

If objFolder Is Nothing Then

MsgBox "This folder doesn’t exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"

End If

If Application.ActiveExplorer.Selection.Count = 0 Then

'Require that this procedure be called only when a message is selected

Exit Sub

End If

For Each objItem In Application.ActiveExplorer.Selection

If objFolder.DefaultItemType = olMailItem Then

If objItem.Class = olMail Then

objItem.Move objFolder

End If

End If

Next

Set objItem = Nothing

Set objFolder = Nothing

Set objInbox = Nothing

Set objNS = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It worked for me after I moved on error resume next to just above where the destination folder is set - then this line:

Set objNS = Application.GetNamespace(“MAPI”) errored - because of the smart quotes.

I fixed them - Set objNS = Application.GetNamespace("MAPI") - and it worked.

Tip of the day: always comment out error handlers when something doesn't work. :)

Rather than saying invalid folder, you might want to create it - although, since the folder exists, it's somewhat pointless to keep it, whether it checks for a folder or creates it.
If objFolder Is Nothing Then
Set objFolder = objInbox.Folders.Add("Family")
End If

if you are a glutton for punishment, you can create folders for months, names, etc - http://www.slipstick.com/developer/file-messages-senders-name/ - but honestly, the fewer folders, the better. I accidentally ran that on an inbox with 3000 messages and ended up with over 500 folders.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thanks but don't understand what I change or do. Can you please explain?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Set objNS = Application.GetNamespace(“MAPI”)

Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

On Error Resume Next
Set objFolder = objInbox.Folders("Family")

See that chunk in bold? Notice how the quotes turn inward and the ones around Family don't? You need to remove the quotes (") and re-type them so they don't turn in.

I'd also move on error resume next so its just above the line where the destination folder is set.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
It works perfect....thanks so so much....

Can we also create it where if the email comes from a certain email, within a certain amount of time, it automatically moves over?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You can look for email addresses and move based on the address (just need to turn it into a run a script macro), but I'm not sure I understand the certain amount of time condition.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
What would be the macro to do it and lets say its 24 hours after received
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
If you are running it 24 hours later, you can't use a run a script rule - that processes mail as it arrives. You'll need to trigger it - i use task reminders to trigger macros, but since this is something you'll run once a day, I'd probably put it in a startup macro, except that it will slow outlook down a little at boot. Or you can click a toolbar button every morning to clean out old mail.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
So not the timing, what so we change so I don't select the emails ...i just run the macro that moves the specific email to the folder?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The second macro at http://www.slipstick.com/developer/file-messages-senders-name/ runs through everything in the folder.

You'll need to check the email address - I'd probably use a case statement-

Select Case LCase(Item.SenderEmailAddress)
Case "mary@domain.com", "john@domain1.com", "sue@domain3.com"
sSenderName = "Family"
Case Else
Goto NextMessage

End Select

If the address matches, this will check the age and go through the macro.
If objVariant.Class = olMail Then
intDateDiff = DateDiff("d", objVariant.SentOn, Now)
' I'm using 40 days, adjust as needed.
If intDateDiff > 40 Then

'<rest of macro
then at the end add this:

NextMessage:
Next

' Display the number of items that were moved.
MsgBox "Moved " & lngMovedItems & " messages(s)."
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I don't understand....can you simple give me the the full code and simply show me the place to put in the email address and the folder it goes to?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I can, if you aren't in a hurry. I have 3 projects I'm working on right now.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thank you. I look forward to getting it as soon aa you can. And as reminder, its not time. Just run the macro and it moves the emails with the specific email i put in the macro to folder i put in the macro. So I don't have to select anything, just run the macro. Thanks much
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Need help with saving "sent items" email automatically to desktop folder

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim fName As String

Const olmsg = 3

fName = "C:\Users\Unknown\Desktop\Sent emails\" & Item.Subject & ".msg"

Item.SaveAs fName, olmsg

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: Need help with saving "sent items" email automatically to desktop folder

This is not the macro I need. Please look back at list of posts before.

- - - Updated - - -

This is not the macro I need. Please look back at list of posts before.
 

Forum Admin

Senior Member
Re: Need help with saving "sent items" email automatically to desktop folder

That script saves them to the desktop. L is moving them to a folder under his inbox.
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Re: Need help with saving "sent items" email automatically to desktop folder

I am sorry If I post my problem in your thread...actually I had a similar problem the code I put does not work for me and the reason that I can think is because of illegal character...I am not that good in coding and do not how can bypass the illegal characters so my script get excuted and can save the file with its subject name,...
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: Need help with saving "sent items" email automatically to desktop folder

i understand but again, i just want to run a macro that moves received emails from a specific email address to a specific folder created in the inbox as a subfolder

- - - Updated - - -

i understand but again, i just want to run a macro that moves received emails from a specific email address to a specific folder created in the inbox as a subfolder
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: Need help with saving "sent items" email automatically to desktop folder

I am sorry If I post my problem in your thread...actually I had a similar problem the code I put does not work for me and the reason that I can think is because of illegal character...I am not that good in coding and do not how can bypass the illegal characters so my script get excuted and can save the file with its subject name,...

You should start your own thread so we don't get the solutions mixed up here. :)

You need to strip illegals. One way is shown in this macro - http://www.slipstick.com/developer/saving-messages-to-the-hard-drive-using-vba/ - and i have some other similar macros that use a function to replace the characters. The save as pdf link at the top of that page uses the function method.

- - - Updated - - -

I am sorry If I post my problem in your thread...actually I had a similar problem the code I put does not work for me and the reason that I can think is because of illegal character...I am not that good in coding and do not how can bypass the illegal characters so my script get excuted and can save the file with its subject name,...





You should start your own thread so we don't get the solutions mixed up here. :)




You need to strip illegals. One way is shown in this macro - http://www.slipstick.com/developer/saving-messages-to-the-hard-drive-using-vba/ - and i have some other similar macros that use a function to replace the characters. The save as pdf link at the top of that page uses the function method.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: Need help with saving "sent items" email automatically to desktop folder

Any update soon?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
P move mails after send to central mailbox-sent items folder Using Outlook 4
S auto move mails from mailboxes to public folders Exchange Server Administration 6
M How can I move e-mails from Outlook (*.msn.co to a CD for stoarage Using Outlook 1
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
I Outlook 2013 Any way to move .OST file to new system? Using Outlook.com accounts in Outlook 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
L Making rule to move email to folder from one O365 domain Using Outlook 1
B Copy/Move Exchange inbox to Pop inbox Using Outlook 4
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
C Move from Outlook 2007 Enterprise (MOE) to Outlook Pro plus 2007 Using Outlook 1
Cdub27 Move Outlook 2016 Contacts to Other Folders - Extremely Slow !! Using Outlook 6
M code to move selected Outlook contacts to another folder Using Outlook 3
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 5
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 0
G Favorites panel entries move around after restarting Outlook 2016 Using Outlook 1
M Move new mail to folder based on sender address Outlook VBA and Custom Forms 2

Similar threads

Top