# Visual Basic and Outlook: Help!

**URL:** <https://boards.straightdope.com/t/visual-basic-and-outlook-help/31659>\
**Category:** Factual Questions\
**Created:** [September 1, 2000, 3:47pm UTC](https://boards.straightdope.com/t/visual-basic-and-outlook-help/31659 "2000-09-01T15:47:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starbury](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Starbury](https://boards.straightdope.com/u/Starbury)\
**Post date:** [September 1, 2000, 3:47pm UTC](https://boards.straightdope.com/t/visual-basic-and-outlook-help/31659/1 "2000-09-01T15:47:29Z")

</div>

Ok…I’ve been trying to set up a function in visual Basic that will automatically send an email without actually opening Outlook.  
Right now, I can get Visual Basic to open up Outlook, with the header and message body filled in, but I would like to be able to have the email sent without forcing the user to click on “send” within Outlook.

Here is the code that I have:

Within a module:

Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” \_  
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, \_  
ByVal lpParameters As String, ByVal lpDirectory As String, \_  
ByVal nShowCmd As Long) As Long

’ Open the default program for sending email messages  
’ Returns True if successful, False otherwise

Public Function OpenEmailProgram(ByVal EmailAddress As String) As Boolean  
Dim res As Long  
res = ShellExecute(0&, “open”, “mailto:” & EmailAddress, vbNullString, \_  
vbNullString, vbNormalFocus)  
OpenEmailProgram = (res \> 32)  
End Function  
'SendMail does almost the same thing as OpenEmailProgram,  
'except that it allows a message to be prewritten

Public Sub SendMail(sDest As String, Optional sSubject As String, \_  
Optional sBody As String, Optional sCC As String)  
ShellExecute 0, vbNullString, “mailto:” & sDest & “?subject=” & sSubject & \_  
“&body=” & sBody & “&CC=” & sCC, 0&, 0&, 1  
End Sub

Then, in a form’s sub:

SendMail “[darmbrust@setfocus.com](mailto:darmbrust@setfocus.com)”, “SendMail Test”, “The function works!!!”

* * *

If anyone has any suggestions on what I could do differently, so that the user does not have to interact with outlook, I would appreciate it.

---

<div class="post-metadata">

**Author:** ![TwistofFate](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@TwistofFate](https://boards.straightdope.com/u/TwistofFate)\
**Post date:** [September 1, 2000, 3:50pm UTC](https://boards.straightdope.com/t/visual-basic-and-outlook-help/31659/2 "2000-09-01T15:50:54Z")

</div>

create a template of the mail you wish to send external to outlook and it should send without opening outlook. call the template itself instead of creating a mail. I’m no good with coding, sorry!
