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!!
Re: Outlook - display certain emails
This is in Outlook 2010 by the way.
Anyone?
Re: Outlook - display certain emails
Why would there be 6 buttons and why would you need a form to list them? Folder view?
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!
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?
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. :/
Re: Outlook - display certain emails
You have to transverse folders. Something like so
Code:
Set otlkFolder = MAPISpace.GetDefaultFolder(olFolderInbox)
Set otlkSomeFolder = otlkFolder.Item("SomeFolder")
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")
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. :/
Re: Outlook - display certain emails
Sorry use Folders, not Items.
Code:
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Negative Feedback")
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!
Re: Outlook - display certain emails
No prob. Glad to help.
Next step is probably better to add the buttons to the ribbon.
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.
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).
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?
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!
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.
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. :/