TheSwamp
Code Red => VB(A) => Topic started by: Kheilmann on July 10, 2006, 06:07:49 PM
-
I'm looking into sending out email messages to different individuals through VBA in AutoCAD, Excel, Word, and Access depending on different criteria. I'm not sure the criteria really matters, but...
It would all be pretty simple...
If a dwg does NOT exist..email drafter
If a .xls does NOT exist..email estimater
If a record in Access does NOT exist..email Parts.
etc.
So my question...Where do I start? What information do I need? Do I need to add any references?
What objects, properties, etc. in Outlook do I need?
Are there better ways to send some message instead of using the company email system?
Since the company email is on an Exch. Server, and that is off site, is there a more secure/stable method to send messages to individuals on the Network?
Thanks in advance for your help....
-
email is probably the best way to go stabilitywise. What do you want to drive this from? Will there be a separate VBA routine for each program and do the names match? If the names match it would be fairly simple to do the check and send the email but it seems to me like a standalone application would probably be the most bestest in this situation if you have the resources to do one. Whichever way you go, you will have to reference the Microsoft Outlook Object Library.
-
Here's some how to do it from Autocad. It will be pretty much exactly the same from excel, access, word, whathaveya.
Sub test()
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)
With objMail
.To = "EstimatorPerson@KheilmannsHizzouse.com"
.Subject = "You're falling down on your end, dude!"
.Body = "Hey Loserboy, The awesomeness that is AutoCAD noticed that you STILL " & _
"haven't done the estimating based on the Drawing: " & _
ThisDrawing.GetVariable("dwgname") & ". Don't make me come down " & _
"there and slap you around again." & vbCrLf & vbCrLf & _
"By the way, say hi to your wife and my kids."
.Display
.Send
End With
Set objMail = Nothing
Set objOL = Nothing
End Sub
-
Bob, you gotta write a programming book! Your sample code clearly states its intent and gets the message across.
:lmao:
-
Thanks, it's good to get positive feedback. I try to do things even in my production code that amuse me if no one else. It occasionaly finds its way into my msgboxes but I tend to stay away from the brake when writing code for other people. Life's to short to take it seriously.
-
That was great Bob! Is that what you call "Learn and Laugh"
-
good one Bob, I hate to admit it but the last line made me LOL..
-
End Sub? I agree it's a classic but to be honest, I totally overuse it.
-
oOoo! you should have quit..
-
Bob, that's golden :D
-
oOoo! you should have quit..
That's the story of my life, Draftek.
-
Word of warning for Kheilman for when he comes back to this, with the .send bit, depending on your security settings, you might get a box that pops up and says something like "A program other than you is trying to send some mail. It might be on purpose, it might be a virus, do you want to send it?" If your security settings are high enough, it might not even allow you to .send. If that's the case, you can always click the send button manually. In fact, you might want to remove the .send so that the sender can modify the message to the sendee if needed.
-
^^ this seems to happen even more if you use the MAPI control instead of adding in a reference to Outlook
-
I have to learn to code so I can do something with message boxes like that!! Even if that is the only reason.
Funny stuff 3.14mp
-
Which begs the question...Maybe even a challenge to all the whizzes (not sure if 'whizzes' is actually a compliment),
Can you program a VBA MSG Box to appear on someone else's computer? Eliminating the problems with E-mail, and the possibility that someone would not check there email for whatever reason......
-
Not that I'm aware of. You could use "net send" but it's not completely reliable.