|
-
Aug 2nd, 2011, 09:00 PM
#1
Thread Starter
Member
Outlook - display certain emails
Still new to VBA so bare with me!
Would like to deal with yesterays emails in a specific folder. I'd like those emails to be pulled up one at a time in their own window. There would be 6 or so buttons. When I hit a button, it will add an entry to a text file and move on to the next email.
I hope this made sense! I don't mind learning what's going on, just need a hand or a tutorial.
Thanks!!
-
Aug 3rd, 2011, 01:21 PM
#2
Thread Starter
Member
Re: Outlook - display certain emails
This is in Outlook 2010 by the way.
Anyone?
-
Aug 10th, 2011, 03:11 PM
#3
Re: Outlook - display certain emails
Why would there be 6 buttons and why would you need a form to list them? Folder view?
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 
-
Aug 11th, 2011, 08:46 AM
#4
Thread Starter
Member
Re: Outlook - display certain emails
I am trying to automate something very tedious. Basically looking for a way to display emails in a certain folder and then have buttons to 'add one' to a text file. Looking for help on reading emails to a gui/menu. Guessing that is possible?
Thanks!
-
Aug 11th, 2011, 11:20 AM
#5
Re: Outlook - display certain emails
So then perhaps adding buttons to the inspector via an AddIn may be the preferred solution.
Would there be a need to disable the buttons for viewing other folders?
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 
-
Aug 11th, 2011, 11:52 AM
#6
Thread Starter
Member
Re: Outlook - display certain emails
One step at a time! Here's what I've got so far:
Code:
Public Sub ReadOutlookMail()
Set otlkApp = CreateObject("Outlook.Application")
Set MAPISpace = otlkApp.GetNamespace("MAPI")
Set otlkFolder = MAPISpace.GetDefaultFolder(olFolderInbox)
For Each MailItem In otlkFolder.Items
MsgBox "Subject: " & MailItem.Subject & vbCrLf & "Body: " & MailItem.Body
Next MailItem
End Sub
This will cycle through each email in my Inbox. What I can't seem to figure out is how to change it to a folder IN my Inbox folder. :/
-
Aug 11th, 2011, 12:01 PM
#7
Re: Outlook - display certain emails
You have to transverse folders. Something like so
Code:
Set otlkFolder = MAPISpace.GetDefaultFolder(olFolderInbox)
Set otlkSomeFolder = otlkFolder.Item("SomeFolder")
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 
-
Aug 11th, 2011, 12:03 PM
#8
Re: Outlook - display certain emails
You cal also transverse directly all in one lne if there is nothing being done at each folder level. Or if you dont want to put in any error handling/checking if a folder exists at each level etc.
Code:
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items("SomeFolder")
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 
-
Aug 11th, 2011, 12:56 PM
#9
Thread Starter
Member
Re: Outlook - display certain emails
Here's what I've got so far:
Code:
Public Sub ReadOutlookMail()
Set otlkApp = CreateObject("Outlook.Application")
Set MAPISpace = otlkApp.GetNamespace("MAPI")
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items("Negative Feedback")
For Each MailItem In oFolder.Items
If MailItem.UnRead Then
MsgBox "Subject: " & MailItem.Subject & vbCrLf & "Body: " & MailItem.Body
End If
Next MailItem
End Sub
The error I get: Run-time error......
In my Inbox is a folder called "Negative Feedback". That's the folder I am trying to deal with. Unfortunately, that error means nothing to me. :/
-
Aug 11th, 2011, 01:33 PM
#10
Re: Outlook - display certain emails
Sorry use Folders, not Items.
Code:
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Negative Feedback")
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 
-
Aug 11th, 2011, 01:50 PM
#11
Thread Starter
Member
Re: Outlook - display certain emails
O.O brilliant! It's working! Many thanks!
Like I said, one step at a time. The next goal is to add several buttons to the msgbox. Each seperate button will add a line(append) to a text file while closing that msgbox.
Again, many thanks!
-
Aug 11th, 2011, 05:34 PM
#12
Re: Outlook - display certain emails
No prob. Glad to help.
Next step is probably better to add the buttons to the ribbon.
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 
-
Aug 11th, 2011, 05:52 PM
#13
Thread Starter
Member
Re: Outlook - display certain emails
By adding buttons to the ribbon, you are starting a new macro. How does the "step" you are currently on continue to a separate macro?
Also, I've notice that the standard msgbox buttons are "ok, cancel, abort...." and if I'm looking for anything different, better to make a form.
-
Aug 11th, 2011, 06:37 PM
#14
Thread Starter
Member
Re: Outlook - display certain emails
Hmm. If 1-3 buttons seems to be all I can get, maybe an input box with a label on the form/msgbox that says each of my categories(1-6).
-
Aug 12th, 2011, 12:24 PM
#15
Re: Outlook - display certain emails
No we would want to add buttons to the email display form as its my understanding that you are opening each email and viewing it?
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 
-
Aug 12th, 2011, 02:52 PM
#16
Thread Starter
Member
Re: Outlook - display certain emails
wow, that sucked.. almost done with a long post and something happened and the post deleted/reset.
Code:
Public Sub ReadOutlookMail()
Set otlkApp = CreateObject("Outlook.Application")
Set MAPISpace = otlkApp.GetNamespace("MAPI")
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).folders("Negative Feedback")
For Each MailItem In oFolder.Items
If MailItem.UnRead Then
MsgBox "Subject: " & MailItem.Subject & vbCrLf & vbCrLf & "Body: " & MailItem.Body
End If
Next MailItem
End Sub
Here's the short version. The code above will open the folder Negative Feedback in my Inbox and only show the unread emails in a msgbox.
What I would 'like' to happen next is to have ~6 buttons. Each button is a category. Hitting one will add a line to the appropriate text file and close that msgbox.
Not sure if the msgbox idea is possible. Might need to make a form. Thoughts/ideas?
Thanks!
-
Aug 12th, 2011, 03:02 PM
#17
Re: Outlook - display certain emails
the way I would do it is to create an AddIn so I could easily add buttons to the Email display form. You would need to download VB Express and install it.
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 
-
Aug 15th, 2011, 07:52 AM
#18
Thread Starter
Member
Re: Outlook - display certain emails
I have come this far. For a newbie, thats a feat! 
I assume it is possible to create a form that would do what I have above? That form could have my buttons?
The way I see it at least, to create AddIns would make a separate button for each 'category' on my ribbon bar. Plus, I know absolutely nothing about AddIns so I would have to learn that from the ground up. :/
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
|