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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send message with outlook express 5 1

Status
Not open for further replies.

filotei

Programmer
Mar 11, 2003
7
RO
I have a code for sending a email message from excel with microsoft outlook. I would like to use the code also for outlook express but I do not know how to set the reference to outlook express 5. Can anyone help me?
Thank you very much.
Below you have the code for microsoft outlook.
Filotei

Code:
Sub Send_Message()

Dim objOL As New Outlook.Application ' this is for Microsoft Outlook
'what will be the reference for Outlook Express 5?
Dim objMail As MailItem

Set objOL = New Outlook.Application ' for outlook express 5?
Set objMail = objOL.CreateItem(olMailItem)

With objMail
    .To = Address
    .subject = Sbj
    .Body = BodyText
    .Send
    
End With
Set objMail = Nothing
Set objOL = Nothing
End Sub
 
Hi,sorry but instead of an answer I got a question. Do you know how I could send an attachment with Microsoft Outlook?
Thanks
 
Hey monivb,

This Is the code I wrote the otherday, it allows you to add an attachment, hope this helps...

Dim fso As FileSystemObject
Dim RespEmail As String
Set fso = New FileSystemObject

'Connect to Contact Table

Dim CnnDB As ADODB.Connection
Dim RstContact As ADODB.Recordset
Set CnnDB = Application.CurrentProject.Connection
Set RstContact = New ADODB.Recordset


'Open Recordset
RstContact.Open Source:="Contact", ActiveConnection:=CnnDB, CursorType:=adOpenForwardOnly, LockType:=adLockPessimistic

'Load Email Addresses
Dim StrEmailAddressSend As String
Dim strEmailAddress As String
Dim ErrResponse As String
Dim olMailItem

'Store HyperLink
Dim HypLink As String
HypLink = "file:///" & "C:\WINDOWS\Desktop\Budget%20Sales%20Vs%20Actual%20Sales" & "%20-%20" & strDate & ".doc"


On Error GoTo ErrHandler:




'Would user like to email contacts to confirm forecast completion
RespEmail = MsgBox("Would You Like To Inform Your Contacts That The Report Is Complete?", vbYesNo, "Email Request")

'If user says yes to email...
If RespEmail = vbYes Then
'Check to make sure the file exists...
If fso.FileExists("C:\WINDOWS\Desktop\Budget Sales Vs Actual Sales" & " - " & strDate & ".doc") = False Then
MsgBox "The File Does Not Exist, Please Save Your File First", vbOKOnly, "File Does Not Exist"
Exit Sub
Else

'Email all contacts neccesary
Dim myOlApp, myItem, myAttachments
Dim fs As Object

'While Not End Of File (sends to all contacts)
Do Until RstContact.EOF = True
'The variable links to relevant Field
strEmailAddress = strEmailAddress & RstContact.Fields("EmailAddress") & "; "
'move record to next pointer
RstContact.MoveNext
Loop

StrEmailAddressSend = Left$(strEmailAddress, Len(strEmailAddress) - 2)

'creates instance of outlook
Set myOlApp = CreateObject("Outlook.Application")
'Creates new email
Set myItem = myOlApp.CreateItem(olMailItem)
'Declares possible attachment transfer
Set myAttachments = myItem.Attachments
'Body text
myItem.Body = vbCrLf & "The New Budget Sales Vs Actual Sales Report Is Complete - " & vbCrLf & vbCrLf & HypLink & vbCrLf & vbCrLf & vbCrLf & "Thanks"
'Subject text
myItem.Subject = "Budget Sales Vs Actual Sales Report Complete"
'Declare email Address
myItem.To = StrEmailAddressSend
'Below line sends a document with email If required.
myAttachments.Add "C:\WINDOWS\Desktop\Document.Doc", olByValue, 200, "Give It a Heading"
myItem.Display

End If

End If
Exit Sub

ErrHandler:
MsgBox Err.Number & " : " & Err.Description
'DoCmd.Close
Exit Sub

ErrExit:
DoCmd.Close

End Sub

Hope this helps,

Sorry filotei but I'm still working on your answer, this code seems to open outlook express at home where it is set as the default mail client, and here at work it works for outlook, if I sort it out i'll get back to you.

(Above code is from Access 200)

Cheers

Sam
 
Hi,

I got this piece of code but get an error
"User defined type not defined".
What is the corresponding declaration ?

Thanks.
Brice.
 

Hi,

I got this piece of code but get an error
"User defined type not defined" on New Outlook.Application.
What is the corresponding declaration ?

Thanks.
Brice.


 
You have to reference the Microsoft Outlook library:
menu Tools -> References ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top