+ Reply to Thread
Results 1 to 7 of 7

Outlook - Help with macro to make folder from number in subject line and move email.

  1. #1
    Registered User
    Join Date
    07-25-2014
    Location
    Home
    MS-Off Ver
    2003
    Posts
    6

    Outlook - Help with macro to make folder from number in subject line and move email.

    Would anyone be able to help me with a macro I need for Outlook.

    I have a situation where I get lots of emails on a daily basis with a subject line like the following

    "Ticket Number # 1234567891: Subject"

    The ticket number is always 10 digits long, and will sometimes have a : after it or a ,. It will always be in the format above with a # then a space then the 10 digit number.

    I would like when I receive these emails for a new folder to be created in the following fashion.

    Current Year> Current Month/Month of Email > Active > Ticket Number from subject of email

    Basically there is already a folder called Tickets, this folder has yearly folders with monthly folders inside those, and each month has a folder for active tickets.

    It would only have to create the current ticket folder, I can manually create the Month folder and Active folder if needed.

    If the ticket folder already exists I would like it to move the email to the current folder. If no folder exists for that ticket number a new one should be created in the Active folder for that month and the email moved to it.

    So the process would be as follows :

    1) Email recieved Date 18/11/2015 Subject : Ticket Number #1234567891: New Ticket

    2) Check for ticket folder in 2015>November>Active

    3) If no ticket folder create folder 1234567891 in Active folder for November

    4) Put email in new folder that was created.

    Would anyone be able to help me with this macro and how I would go about adding it to Outlook to run automatically or on a button press?

    I have attempted to adapt the code here http://ccm.net/forum/affich-39527-ou...eating-folders but have not been successful. I am not sure where the code goes and how to adapt it to match my scenario.

    I would be very grateful as this will save me an immense amount of time.
    Last edited by TrevP; 11-18-2015 at 06:26 PM.

  2. #2
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    I changed RegEx to InStr. Less efficient but it works.


    Please Login or Register  to view this content.
    http://www.slipstick.com/developer/h...ks-vba-editor/

    http://www.howto-outlook.com/howto/macrobutton.htm

    https://msdn.microsoft.com/en-us/library/ee814736.aspx
    Last edited by skatonni; 11-19-2015 at 06:26 PM.
    To mark "Solved" go to Thread Tools.

  3. #3
    Registered User
    Join Date
    07-25-2014
    Location
    Home
    MS-Off Ver
    2003
    Posts
    6

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    Hi,

    This looks perfect, however I have pressed Alt + F11, and pasted this into ThisOutlookSession, saved and restarted outlook and it does not seem to be doing anything. Do I need to do something to activate the macro or should it just be running always?

    I have "enable all macros" enabled and have tried adding Macro Application_Startup() as a button and pressing that also and does not seem to do anything.
    Last edited by TrevP; 11-19-2015 at 08:09 PM.

  4. #4
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    If you set up correctly ItemAdd is always on.

    Select a test mail. Open the VBA editor and step through with F8

    Please Login or Register  to view this content.
    This will manually call ItemAdd. I suggest testing before running any code.

    http://www.cpearson.com/excel/DebuggingVBA.aspx

  5. #5
    Registered User
    Join Date
    07-25-2014
    Location
    Home
    MS-Off Ver
    2003
    Posts
    6

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    When I step through with F8 after selecting the test sub it works,

    However it put them in a folder called 11 within the year folder. I have now fixed this by changing to sFolderMonth to MonthName(CStr(Month(.ReceivedTime)))

    Is it possible to run this on my entire inbox?

    And how do I get this running always automatically for new incoming mail? It does not appear to be running in the background, it only actually does anything when i run through the test sub.

    If I F8 from the "Application_Startup" Sub, it just loops through and never leaves the startup sub.

    It currently works perfectly if I choose the test sub in VBA editor and hold down F8 while selecting a folder of correct emails. I just need this to work automatically.
    Last edited by TrevP; 11-20-2015 at 09:19 PM.

  6. #6
    Registered User
    Join Date
    07-25-2014
    Location
    Home
    MS-Off Ver
    2003
    Posts
    6

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    I have just copied the majority of the code into a module and changed the sub to Sub TestingMailRule(Item As Outlook.MailItem)
    .

    I then set this as a rule to run automatically when an email with the subject arrives. And it works perfectly this way. Also allows me to run on an entire folder.

    Is this the way I was supposed to set it up, and if not is there any downside to doing it this way?

    Either way thanks so much for the code this will save me hours of time every day.

  7. #7
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Outlook - Help with macro to make folder from number in subject line and move email.

    Rules with RunAScript code break. ItemAdd does the same as rules without breaking.

    ItemAdd code goes in ThisOutlookSession. If already there, you may find something here that you can use to determine why your ItemAdd code does not work.

    http://www.slipstick.com/developer/p...s-with-macros/

    http://www.outlookcode.com/article.aspx?id=62

+ 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: 06-18-2015, 05:35 PM
  2. 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
  3. Replies: 0
    Last Post: 09-12-2013, 07:43 AM
  4. Move an email to a folder in outlook using macro
    By Arunkumark in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 07-11-2013, 09:33 AM
  5. [SOLVED] Macro to Rename Outlook Attachment Same as Email Subject
    By sandy_314 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2013, 09:59 AM
  6. Replies: 8
    Last Post: 05-17-2013, 01:53 AM
  7. Replies: 0
    Last Post: 08-16-2011, 02: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