+ Reply to Thread
Results 1 to 7 of 7

mails moving

  1. #1
    Registered User
    Join Date
    09-08-2022
    Location
    india
    MS-Off Ver
    office 16
    Posts
    4

    mails moving

    New to VBA => Please refer to below codes- I want to move different sender emails to different different subfolders in outlooks, in my excel Range a1:a3 i have sender names, i will add folder names in range b1:b3, so i want that each sender email to move into respective folder by reffering to excel range please help..........

    Please Login or Register  to view this content.
    Last edited by hemanttt; 09-13-2022 at 12:01 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Move different sender emails to different sub-folders of outlook using excel range

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    09-08-2022
    Location
    india
    MS-Off Ver
    office 16
    Posts
    4

    Re: Move different sender emails to different sub-folders of outlook using excel range

    Somebody help pls

  4. #4
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Move different sender emails to different sub-folders of outlook using excel range

    try below, untested as i have no outlook data

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-08-2022
    Location
    india
    MS-Off Ver
    office 16
    Posts
    4

    Re: Move different sender emails to different sub-folders of outlook using excel range

    Hello Sir,

    Thanks for coming to help me Really appreciated... Thanks for your time.

    Its perfectly working after some little modifications, really appreciated your help.

    You are the first one on all online forums gave exact solution

    THANKS...!!!!!
    Last edited by hemanttt; 09-11-2022 at 03:33 PM.

  6. #6
    Registered User
    Join Date
    09-08-2022
    Location
    india
    MS-Off Ver
    office 16
    Posts
    4

    Re: Move different sender emails to different sub-folders of outlook using excel range

    Sir, I worked on your given solution and accordingly i modified my code, it was working file but now it is giving "Automation error"

    Please guide me how i can resolve this error ?

    [code]

    Sub MoveItems_to_outlook_folder()

    Dim myNameSpace As Outlook.Namespace
    Dim myInbox As Outlook.Folder
    Dim myDestFolder As Outlook.Folder
    Dim myItems As Outlook.Items
    Dim myItem As Object
    Dim folder_name As String

    Dim Recip As Outlook.Recipient

    Set myNameSpace = GetNamespace("MAPI")
    Set Recip = myNameSpace.CreateRecipient("ABC.com")
    Recip.Resolve
    If Recip.Resolved Then

    Set myInbox = myNameSpace.GetSharedDefaultFolder(Recip, olFolderInbox) ' Getting automation error at this line
    'myInbox.Display
    End If
    Set myItems = myInbox.Items

    Dim wbk As Workbook
    Dim ws As Worksheet

    Set wbk = Workbooks("Example.xlsm")
    Set ws = wbk.Worksheets("Sheet1")

    Dim varSearchTerms As Range 'converted to range
    Set varSearchTerms = ws.Range("A2:A3")

    Dim varSearchTerm As Range 'converted to range

    For Each varSearchTerm In varSearchTerms

    folder_name = varSearchTerm.Offset(0, 1).Value
    Set myItem = myItems.Find("[SenderName] = '" & varSearchTerm & "'")

    Set myDestFolder = myInbox.Parent.Folders(folder_name)
    'myDestFolder.Display


    While TypeName(myItem) <> "Nothing"
    myItem.Move myDestFolder
    Set myItem = myItems.FindNext
    Wend

    Next
    Set myNameSpace = Nothing
    Set myItem = Nothing
    Set myDestFolder = Nothing
    Set myItems = Nothing

    End Sub

  7. #7
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: mails moving

    what is the olFolderInbox?

    im not yet an expert manipulating data in outlook maybe someone can take a look

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 12-08-2019, 05:30 PM
  2. macro to loop through all folders and sub folders of outlook and save to excel
    By excelhelpseeker in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 10-27-2016, 03:24 AM
  3. Set up Outlook rule to move eMails to respective sub folders
    By Karen615 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 04-22-2015, 02:30 PM
  4. Outlook Rules - moving emails from a sender in a specific address book
    By UKRyan in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 12-22-2014, 11:12 AM
  5. Save an Outlook attachment and move the email to a folder based and sender
    By db16886 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 09:49 PM
  6. Replies: 0
    Last Post: 02-09-2012, 12:30 PM
  7. [SOLVED] How do move folders from web based email account to outlook?
    By Tracy in forum Excel General
    Replies: 1
    Last Post: 11-18-2005, 04:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1