Results 1 to 6 of 6

Thread: [RESOLVED] Auto Macro

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    8

    [RESOLVED] Auto Macro

    I have a macro in Outlook, i need it to run everytime a new mail comes to my inbox...how do i do that??
    Last edited by subramm; Feb 4th, 2004 at 08:50 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    In the VB editor (Press Alt + F11), add this code.
    VB Code:
    1. Private Sub Application_NewMail()
    2.  
    3.     Call YouMacroName
    4.  
    5. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    8

    Thanks

    Thanks for that, it works. My macro manipuates my emails and stores them on some form outside. Now sometimes i get two mails at the same time, so macro works fr the first email and does nt fr the other as it is nt new nemore. how do i gt the macro 2 wrk fr all unread mails...

    ne help wud b gr8

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You need to loop through the Inbox folder and check if the items
    are new mail or not.
    VB Code:
    1. Private Sub Application_NewMail()
    2.  
    3.     Dim oNS As Outlook.NameSpace
    4.     Dim oInbox As Outlook.MAPIFolder
    5.     Dim oEmail As Outlook.MailItem
    6.     Dim i As Integer
    7.  
    8.     Set oNS = Application.GetNamespace("MAPI")
    9.     Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
    10.     i = 0
    11.     'Loop through the inbox marking unread emails as read.
    12.     Do While oInbox.UnReadItemCount > 0 And i < oInbox.Items(i).Count
    13.         i = i + 1
    14.         If oInbox.Items(i).UnRead = True Then
    15.             Set oEmail = oInbox.Items.Item(i)
    16.             oEmail.UnRead = False
    17.             'Do more stuff here
    18.             '...
    19.             '...
    20.             '...
    21.             Set oEmail = Nothing
    22.         End If
    23.         Set oInbox = Nothing
    24.         Set oInbox = oNS.GetDefaultFolder(olFolderInbox)'Refresh
    25.     Loop
    26.  
    27. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    8

    Absolutely great

    Thanks a lot mate!! it works like a beauty now...much appreciated the help

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Your welcome, glad to help.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width