|
-
Jan 2nd, 2004, 03:12 AM
#1
Thread Starter
New Member
[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.
-
Jan 6th, 2004, 03:03 PM
#2
In the VB editor (Press Alt + F11), add this code.
VB Code:
Private Sub Application_NewMail()
Call YouMacroName
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 4th, 2004, 04:51 AM
#3
Thread Starter
New Member
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
-
Feb 4th, 2004, 01:20 PM
#4
You need to loop through the Inbox folder and check if the items
are new mail or not.
VB Code:
Private Sub Application_NewMail()
Dim oNS As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oEmail As Outlook.MailItem
Dim i As Integer
Set oNS = Application.GetNamespace("MAPI")
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
i = 0
'Loop through the inbox marking unread emails as read.
Do While oInbox.UnReadItemCount > 0 And i < oInbox.Items(i).Count
i = i + 1
If oInbox.Items(i).UnRead = True Then
Set oEmail = oInbox.Items.Item(i)
oEmail.UnRead = False
'Do more stuff here
'...
'...
'...
Set oEmail = Nothing
End If
Set oInbox = Nothing
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)'Refresh
Loop
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 4th, 2004, 08:26 PM
#5
Thread Starter
New Member
Absolutely great
Thanks a lot mate!! it works like a beauty now...much appreciated the help
-
Feb 5th, 2004, 11:37 AM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|