New e-mail message with subject line in VBA

New e-mail message with subject line in VBA

Anonymous
Not applicable
408 Views
5 Replies
Message 1 of 6

New e-mail message with subject line in VBA

Anonymous
Not applicable
How do open a new e-mail message with the proper address and the subject line filled out in VBA? Joshua Modglin
0 Likes
409 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
API call to shell32.dll?

jmodglin wrote:

> How do open a new e-mail message with the proper address and the
> subject line filled out in VBA? Joshua Modglin
0 Likes
Message 3 of 6

Anonymous
Not applicable
I use this function for my Access database. You must have Outlook reference
selected.

CreateNewOutLookEmail "rob@stardsign.com"

Sub CreateNewOutLookEmail(email As String)
Dim olApp As Object
Dim mailItem As mailItem
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err > 0 Then
Set olApp = CreateObject("Outlook.Application")
End If
Set mailItem = olApp.CreateItem(olmailItem)
With mailItem
.To = email
.ReadReceiptRequested = True
.Body = "The body goes here"
.Display
End With
Set olApp = Nothing
End Sub




--
|
-+-------------------------------------------------
| Rob Starz
| Stardsign cad solutions
| AEC Designer / Consultant / Developer
| iC - AEC Information Center
| www.stardsign.com/aecic.html
| "can we make it any easier?!"
0 Likes
Message 4 of 6

Anonymous
Not applicable
Rob,
That looks like exactly what I want but what if the user does not have
or does not use Outlook. In lisp I can write the code in one line and it
will call the default email program. Is there not a simpler way??? Thanks
for the code Rob. At this moment is looks like I will just go to using lisp.


Joshua Modglin

"Rob Starz" wrote in message
news:B3E0A3FF003A6FE4AB6FB2D17FD8C393@in.WebX.maYIadrTaRb...
> I use this function for my Access database. You must have Outlook
reference
> selected.
>
> CreateNewOutLookEmail "rob@stardsign.com"
>
> Sub CreateNewOutLookEmail(email As String)
> Dim olApp As Object
> Dim mailItem As mailItem
> On Error Resume Next
> Set olApp = GetObject(, "Outlook.Application")
> If Err > 0 Then
> Set olApp = CreateObject("Outlook.Application")
> End If
> Set mailItem = olApp.CreateItem(olmailItem)
> With mailItem
> .To = email
> .ReadReceiptRequested = True
> .Body = "The body goes here"
> .Display
> End With
> Set olApp = Nothing
> End Sub
>
>
>
>
> --
> |
> -+-------------------------------------------------
> | Rob Starz
> | Stardsign cad solutions
> | AEC Designer / Consultant / Developer
> | iC - AEC Information Center
> | www.stardsign.com/aecic.html
> | "can we make it any easier?!"
>
>
>
>
0 Likes
Message 5 of 6

Anonymous
Not applicable
In that case use the Shell32.dll API

<<>

'Declare these in a module:
Public Const SW_SHOW = 1

Public 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

'Now everything for the command is set up.
'Add a public subroutine for use throughout
'your project like this:

Public Sub Navigate(frm As Form, ByVal WebPageURL As String)

Dim hBrowse As Long
hBrowse = ShellExecute(frm.hWnd, "open", WebPageURL, "", "", SW_SHOW)

End Sub


If you use mailto:... instead of an url the default mail-program is
launched:
Navigate "http:..."
or
Navigate "mailto:xxx@yyy.com"



--
|
-+-------------------------------------------------
| Rob Starz
| Stardsign cad solutions
| AEC Designer / Consultant / Developer
| iC - AEC Information Center
| www.stardsign.com/aecic.html
| "can we make it any easier?!"
0 Likes
Message 6 of 6

Anonymous
Not applicable
Rob, thanks, much more concise and universal. I forgot to mention that I am just a beginner with VBA. I am having problems getting your code to work. With the Public Declare Function it is giving me the error message "Expected: line number or label or statement or end of statement" and will not continue (So I have not yet been able to display an e-mail message as of yet.). Do you know why??? Joshua Modglin
0 Likes