Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Outlook Code? 1

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
I just learned it is possible to use VBA code in Outlook. Looking at it, I see how to insert a module, but I am not sure if that is how I would go about it or not. I suck with VBA and am not much better with Outlook.

Everyone uses Outlook at my work. Right now when we get an email, I get a small message box that pops up dont next to the clock. Unfortunately when I am focused on minute things on the screen, I will never see that pop-up way down int he corner and sometimes when I get an email asking me to come help someone, I wont see the email four a couple hours.

What I want to do....

1) Create code that will attach to my Outlook so that every day when I open outlook it will automatically open as well. In excel the modules we place code in seem to be attached to files and not excel itself. For outlook I want to make sure it opens with the program.

2) When I get new email, I want a message to pop up in the middle of my monitor telling me to check my mail and I want it to stay there until I click OK. That way if I am away from my computer it will still be there when I get back.

Is this possible with Outlook?



 
Replies continue below

Recommended for you

Wow, that sounds super annoying. The pop up in the task bar was annoying enough; I turned that off. My attitude toward email is: "If you email me, I'll get to it when I get to it. If it is urgent, call me or come talk to me." If something takes over my screen every 10 minutes, I'll never get anything done.

Be careful what you wish for...

[edited for clarity]
 
Thanks cowski

I dont get a lot of emails at work. The ones I do get, 99% of them are from people I work with. Either Leaders sending me a job request or someone needing help on one program or another.

To be honest though, I am unsure how to email you. I see the button for Email Thread but not sure if that goes to you or what. I clicked on your name and I dont see anything there on how to email you. Sorry for my ignorance in this area.
 
Ken,

Every Microsoft application has VBA capabilities “built in.” Excel, Word, Outlook, PowerPoint, Access all can be automated. BTW, in each application, including Excel, the code modules are saved WITH the Workbook, Document, Presentation.

Outlook is an outlier in many respects. I’d suggest posting your question in Tek-Tips VBA Visual Basic for Applications (Microsoft)

I am not conversant with the Outlook Object Model, although I’ve done some coding in Outlook VBA. There may be some here at Eng-Tips and there are a few at Tek-Tips.

Whatever you decide to do, you’ll need to do a lot of “heavy lifting” on your own. You’ll be building your VBA toolbox and “I just learned...” will become a more regular utterance.

Here’s a valuable tool that I use regularly...
How to use the Watch Window as a Power Programming Tool
Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
And definitely no hurry at all. I have lived without it in this company since 2010, I can go a while longer. lol
 
Thanks Skip

I will probably do that. I just looked at the Powerful programming Tool you gave a link to. Kind of scary reading that post. Afraid it may be stepping into something way above my head. lol Though I seem to make it a habit of getting myself into these messes anyway, so I will be stepping in. lol

Im already saying "I just learned...” quite often when it comes to the basic stuff of VBA. lol
 
At 76, I still utter those words and will past my dying day.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You'd be better off ignoring any VBA and just setting Outlook to run on startup, at least for the first part of your question.

Its likely possible to use VBA to generate a message window whenever a new email is received, but I'd agree wholeheartedly with cowski, it'll be so annoying and counterproductive that you'd turn it off again. You're better off changing your workflow or habits than attempt to get Outlook to alert you to new emails. There's probably a setting somewhere to make the new email notification persistent, which would remove all need for VBA.

There's plenty that VBA can do for you, I'd suggest that this case isn't one of them.



EDMS Australia
 
If you get 50+ emails a day, I can see where this would be ridiculous. When you get 3 to 10 emails a day and most of them are emails you want to act upon asap, this would be helpful.

I have messed with the pop-up in the past. However I change it, it still stays a small mesage down in the corner that I dont see pop-up.

At this moment, I have three windows explorer folders, Outlook, the internet, two files of excel, WESS (GM Program), and NX open and spread out across two monitors. When I am at my desk, I am focusing on other areas of the monitor and dont see the pop-up. (My eyes getting worse and worse dont help) and I might be focusing on the job I am doing for hours at a time. I try to remember to check my email, but too often I am too focused on other things and it doesnt even come to mind.

Believe me, I have given it thought and I know this isnt something most people would want. Not everyones situation is like yours though. I would rather it force my attention to the fact I have an email once every couple hours, rather than leave a boss waiting for an hour and a half to get something done that should have taken me ten minutes.
 
What version of Outlook?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Microsoft Office Professional Plus 2010

Version: 14.0.7116.5000 (32-bit)
 
Unfortunately we dont have sound hooked up to our computers. People can listen to headphones but they hook them up to their phones and Ipods.
 
Here's a link that tells you how to create a shortcut that will run your macro whenever Outlook starts:

Your shortcut will be something like:
"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE" /autorun mainMailWatcher
Don't change the "mainMailWatcher" part.

Here's some info on how Outlook stores and saves code (basically it sucks):
Follow the instructions for importing.

You will have to enable macros for this to work. Your default macro security settings probably block all macros without even telling you. The macro will let you know if it starts with a message box that says "Watching for mail..."

Here are the code Module, Class Module, and UserForm you need to import. It doesn't lock up your whole PC until you dismiss the message, but it is big and stays on top.



 
Sorry Handleman, I never saw your reply until today.

Between Handleman's and MintJulep's replies, I was able to get this working. Unfortunately there is one thing happening that actually makes it worse for me if I cant fix it. lol It pops up a message box right in the middle of the screen. That is great. Unfortunately, it doesnt make that message box the focused window. So if I am working on excel and staring at a zillion numbers and I get an email, that message box pops up but stays in the background behind my excel or whatever program I am working on. And so I never see it. To make it worse, the tiny notification Outlook usually pops up in the corner of the screen wont pop up until after I click OK on that message box, which hides behind the program I am on. lol So now I dont even get that tiny notification to let me know. lol

Still, this is a big leap forward with only a small problem to figure out.

In my searching I am finding some pieces of code that might work but so far none do, though that is very likely because I have no idea how to place it in this code that MintJulep provided in his/her link. . lol

 
Sooo.... Part of my stuff was a giant message box (actually a UserForm) that does make itself always on top. What I posted is a complete solution. If you try to take bits and pieces of it and put it into other partial solutions without knowing what you're doing you will end up.... well, exactly where you are.

Sorry... Not trying to be an ass. But I put some effort into actually writing the thing that did what you asked for instead of exactly what the code in the link does.
 
Sorry... I have switched over and trying yours. I imported all four files and I copied the module with ....
Private Sub Application_NewMailEx ..... over to ThisOutlookSession. It wants to work but it gives me...

Error: 5 Invalid procedure call or argument.

I have copied all of them to the ThisOutlookSession and tried moving them around. The best I got so far was for that error to come up and when I hit OK, the big message popped up. I havent gotten back to that happening since. lol

Did I say I suck with code?
As of right now, this is what that code looks like.... (Dont laugh if I messed it up.... nah, go ahead and laugh. You might as well enjoy helping me.) I will look to see if there is a reply in the morning.





Dim mymailwatcher As clsMailWatcher

Dim WithEvents myOutlook As Outlook.Application

Sub mainMailWatcher()
MsgBox "Watching for mail..."
Set mymailwatcher = New clsMailWatcher
End Sub


Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim strIDs: strIDs = Split(EntryIDCollection, ",")
Dim oMail As MailItem, nIndex
Dim oNameSpace As NameSpace
Set oNameSpace = Application.GetNamespace("MAPI")

On Error GoTo koniec
For nIndex = 0 To UBound(strIDs)
Set oMail = oNameSpace.GetItemFromID(strIDs(nIndex))
MsgBox "Message is knocking to you: " & _
oMail.SenderName & vbCr _
& oMail.FormDescription & vbCr _
& oMail.ReplyRecipients & vbCr _
& oMail.Recipients(1).Address, vbInformation, "Your Outlook Alert"
Next
Exit Sub
koniec:
MsgBox "Error: " & Err.Number & " " & Err.Description, vbExclamation, "VBATools.pl"

End Sub


Private Sub Class_Initialize()
Set myOutlook = Outlook.Application
End Sub

Private Sub myOutlook_NewMail()
'MsgBox "You've got mail!"
frmMailMessage.Show
End Sub


P.S.
I love the message. lol
 
OK... Get rid of everything in the link that MJ posted. It is extraneous. The stuff I wrote doesn't need to go in ThisOutlookSession or whatever. All you have to do is import the 3 things. Just leave them exactly as imported. Then make your Outlook shortcut as per the instructions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor