Nov 24 2020 05:23 AM - edited Nov 24 2020 05:24 AM
Hi every One, greetings
I have to do the following.
I need a vba for, moving a mail in outlook inbox to a specified folder in outlook based on either Sender name or sender mail or mail subject, commanding from excel.
I have browsed for this all over internet, and found only outlook VBAs, which I think it will create security issues. ..
Could any "Master Minds in VBA" help on this????
Nov 24 2020 07:36 AM
I cannot follow your plan, probably from the translation.
It would be beneficial if you insert a file (without sensitive data), if necessary, and explain your plans on the basis of this file.
An additional advantage of getting a quick and precise solution proposal here is if you would send us your Excel version and your operating system.
Nonetheless, yesterday I had a topic that was similar, attached the file that I sent, maybe it fits into your plan.
I would be happy to know if I could help.
Nikolino
I know I don't know anything (Socrates)
* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.
Nov 25 2020 06:02 AM
@NikolinoDE Hi- Thanks for coming up for helping me.
I have attached the code herewith-please find it.
this code will help me to save the attachment from outlook to a specific folder in my PC.
What I need is, to move the mail in outlook inbox to a folder in outlook after clicking this VBA.
So ultimately, I will save the attachment and will move this to a folder in outlook. so no open files inbox to attend!!!!
Nov 25 2020 06:04 AM
Hey Master Minds
Please help me on this.
Just to describe again,
I have attached the code herewith-please find it.
this code will help me to save the attachment from outlook to a specific folder in my PC.
What I need is, to move the selected mail in outlook inbox to a folder in outlook after clicking this VBA.
So ultimately, I will save the attachment and will move this mail to a folder in outlook. so no mails inbox to attend!!!!
Nov 25 2020 06:41 AM
I think that this will solve your problem.
MailItem.Move method (Outlook)
https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.move
Thank you for your understanding and patience
Wish you a nice day.
Nikolino
I know I don't know anything (Socrates)
Nov 25 2020 10:42 PM
I tried that, but showing the below screen shot and yellow highlighted the code below.
Please note: I did it in Excel VBA
Nov 25 2020 11:49 PM
I don't think I'm getting any further with Outlook.
That's why I forwarded your question to the Outlook group / community.
Maybe it needs some settings in Outlook, which I don't know.
Whatever the case, let's wait for the response and then we'll see.
Question Link:
Sorry that I haven't been able to offer you a solution until now.
Thx for your Tiem and patience
Nikolino
I know I don't know anything (Socrates)
Nov 26 2020 09:50 AM
Maybe this approach could help you resolve your issue.
Please adjust in your code
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem Then
SaveSentMail Item
End If
End Sub
Private Sub SaveSentMail(Item As Outlook.MailItem)
Dim Inbox As Outlook.MAPIFolder
Dim Subfolder As Outlook.MAPIFolder
If Item = "Nikolino" Then
Set Inbox = Application.Session.GetDefaultFolder(5)
Set Subfolder = Inbox.folders("0200 Nikolino").folders("General")
Set Item.SaveSentMessageFolder = Subfolder
End If
Sorry that I haven't been able to offer you a quick, acceptable solution until now.
Will keep you updated
Thank you for your patience and time.
Nikolino
I know I don't know anything (Socrates)
Nov 27 2020 09:02 PM
Nov 28 2020 05:15 AM
@NikolinoDE It will not work. Could you paste the whole code then.
Nov 28 2020 01:24 PM
I was also able to pick this up.
From one folder to another.
Thank you for your understanding and patience
Nikolino
I know I don't know anything (Socrates)
Nov 28 2020 08:36 PM
still i am facing this highlighted area, with an error message
Actually i want to move from Inbox to client a mail based on Sender email Address.!!!
Nov 29 2020 04:06 AM
Nov 29 2020 04:10 AM
Nov 29 2020 04:25 AM
as additional info:
Xiant Filer: https://www.softpedia.com/get/Office-tools/Other-Office-Tools/Xiant-Filer.shtml
VBOffice SAM: http://www.vboffice.net/en/products/sam
*The third-party products that this article discusses are manufactured by companies that are independent of me. I makes no warranty, implied or otherwise, about the performance or reliability of these products.
Thank you for your patience and time.
Nikolino
I know I don't know anything (Socrates)
Nov 30 2020 04:39 AM - edited Nov 30 2020 04:40 AM
Nov 30 2020 05:30 AM
As far as I could see it is difficult for you to do this in Excel with VBA.
Is also understandable, since VBA has a lot of manual cuts / code changes so that it functions as it should be in the respective environment.
Therefore I would like to offer you this suggested solution via Outlook.
Here, the sent emails are moved by the Outlook rules.
Move sent items to other Outlook folders.
When you send a message, a copy of the message is moved to the Sent Items folder.
However, this is not necessarily useful if you e.g.
Collect your correspondence with different people / companies etc. in different folders.
You then always have to look for the copy from the "Sent Items" folder
and then move it into the respective folder.
Guess this is your problem.
I would like to show you a solution with Outlook to the problem.
Go to Outlook.
You must now first switch off the send copy function.
To do this, go to the Tools / Options menu - Settings tab in Outlook and click the E-Mail Options button.
Now a new window will open, remove the check mark under “Save message copies in the Sent Items folder” and then close all windows using the OK button.
Now you need to define a rule.
To do this, go to the Tools / Rules and Notifications menu in Outlook - E-Mail Rules tab and click here
Click the "Create rule without template" button.
Now select Check messages after sending and then click Next.
In the next window, set an account name for "via account" and now you have to select an account in the rule description (below).
Then click Next.
Now put a tick under “Move a copy of this to the target folder” and select an appropriate folder.
Now a predefined account will be sent and saved in the specified folder.
If you want to sort your sent messages by person, repeat steps 1 and 2 and put a tick under “sent to a person / distribution list” in the conditions. Select the name from the address book / distribution list.
Warning: All outgoing messages are moved to the specified folder and are no longer stored in the "Sent items".
I hope that I was able to help you a bit and I wish you every success with your project.
Wish you a nice day
Thank you for your patience and time.
Nikolino
I know I don't know anything (Socrates)
Dec 10 2020 04:21 AM
HI @NikolinoDE
FINALYY I HAVE FOUND THE CODE, CHECK IT.
Option Explicit
Sub INC_Data()
Dim ol As Object 'Outlook.Application
Dim ns As Object 'Outlook.Namespace
Dim inboxFol As Object 'Outlook.Folder
Dim subFol As Object 'Outlook.Folder
Dim itm As Object
Dim mi As Object 'Outlook.MailItem
Dim att As Object 'Outlook.Attachment
Dim fso As Object 'Scripting.FileSystemObject
Dim dirName As String
'Some Set Ups
Set fso = CreateObject(Class:="Scripting.FileSystemObject")
Set ol = CreateObject(Class:="Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set inboxFol = ns.GetDefaultFolder(6) 'olFolderInbox
Set subFol = inboxFol.Folders("Client")
dirName = "D:\XYZ"
If Not fso.FolderExists(dirName) Then
fso.CreateFolder dirName
End If
'Finding the search item from Oulook Inbox
For Each itm In inboxFol.Items
If itm.Class = 43 Then
Set mi = itm
If mi.Attachments.Count > 0 And InStr(mi.SenderEmailAddress, "xxxxxxx@inc.ae") Then
'Saving Attachments to a folder
For Each att In mi.Attachments
If Right(att.Filename, 4) = "xlsm" Then
att.SaveAsFile dirName & "\" & Range("Ad2").Text & ".xlsm"
End If
Next att
'Move mail item to subfolder
mi.Move subFol
End If
End If
Next itm
End Sub
Jan 30 2021 08:26 AM