Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

VBA to create Outlook Express email ?? 1

Status
Not open for further replies.

thebigcheese

Technical User
Mar 19, 2001
10
CH
The following code allows you to send a mail message via Outlook, however I want to know if it is possible to send an email via Outlook Express?

Does anyone have code samples?

Sub SendMail(strMsg as String)
Dim OlkApp As Object 'Outlook Application
Dim NewMail As Object 'Mail Item
Set OlkApp = CreateObject("Outlook.Application")
Set NewMail = OlkApp.CreateItem(olMailItem)
With NewMail
.To = "John Doe"
' or you can put .To = "jdoe@industry.com"
.Body = "This is your message"
.Subject = strMsg
.Importance = 2 'olImportanceHigh not understood by SBL.
.Send
End With
End Sub

Thanks!
 
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
Sub SendEMail()
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Dim r As Integer, x As Double
For r = 2 To 4 'data in rows 2-4
' Get the email address
Email = Cells(r, 2)

' Message subject
Subj = "Your Annual Bonus"

' Compose the message
Msg = ""
Msg = Msg & "Dear " & Cells(r, 1) & "," & vbCrLf & vbCrLf
Msg = Msg & "I am pleased to inform you that your annual bonus is "
Msg = Msg & Cells(r, 3).Text & "." & vbCrLf & vbCrLf
Msg = Msg & "William Rose" & vbCrLf
Msg = Msg & "President"

' Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")

' Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
' Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg

' Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus

' Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%s"
Next r
End Sub
 
forgot this bit,

email.gif

 
Do you know of a way to attach more than 1 file to an email? Using Outlook Express.

Regards

Sarge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top