Author Topic: Sending email/msg with VBA thru Acad, word, etc.  (Read 6340 times)

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
Sending email/msg with VBA thru Acad, word, etc.
« 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....

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #1 on: July 10, 2006, 06:23:48 PM »
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.

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #2 on: July 10, 2006, 06:40:17 PM »
Here's some how to do it from Autocad.  It will be pretty much exactly the same from excel, access, word, whathaveya.

Code: [Select]
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

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #3 on: July 10, 2006, 07:55:56 PM »
Bob, you gotta write a programming book! Your sample code clearly states its intent and gets the message across.
:lmao:
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #4 on: July 10, 2006, 07:59:43 PM »
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.

Arizona

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #5 on: July 11, 2006, 06:13:14 AM »
That was great Bob! Is that what you call "Learn and Laugh"

Draftek

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #6 on: July 11, 2006, 07:54:48 AM »
good one Bob, I hate to admit it but the last line made me LOL..

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #7 on: July 11, 2006, 08:27:02 AM »
End Sub?  I agree it's a classic but to be honest, I totally overuse it.

Draftek

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #8 on: July 11, 2006, 09:46:45 AM »
oOoo! you should have quit..

nivuahc

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #9 on: July 11, 2006, 11:25:33 AM »
Bob, that's golden :D

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #10 on: July 11, 2006, 11:30:42 AM »
oOoo! you should have quit..
That's the story of my life, Draftek.

Bob Wahr

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #11 on: July 11, 2006, 11:34:30 AM »
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.

BAshworth

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #12 on: July 12, 2006, 10:41:58 AM »
^^ this seems to happen even more if you use the MAPI control instead of adding in a reference to Outlook

Maverick®

  • Seagull
  • Posts: 14778
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #13 on: July 12, 2006, 11:11:20 AM »
  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

Kheilmann

  • Guest
Re: Sending email/msg with VBA thru Acad, word, etc.
« Reply #14 on: July 13, 2006, 11:06:31 AM »
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......