noycez Level: VB Guru

 Registered: 14-10-2002 Posts: 79
|
Re: Sending Excel,Word File by e-mail
I got this procedures and fucntions from my compilations, all you have to do is to figure out how to add recipients and attachments, though i haven't tried the codes yet
---------------------------------------------
Private NoToRecp As Integer
Private NoCCRecp As Integer
Private NoAttach As Integer
Private x As Integer
Private AddressTo(200) As String
Private AddressCC(200) As String
Private AttachFile(200) As String
Public Enum RecipType
ToRecip
CCRecip
End Enum
'This code will send your message
Public Sub SendMail(vbSubject As String, vbMessageText As String)
On Error GoTo Message_Sent_Error
Dim vbmailobj As Object
Set vbmailobj = CreateObject("Outlook.Application")
With vbmailobj.CreateItem(olMailItem)
For x = 1 To NoToRecp
.Recipients.Add AddressTo(x)
Next x
If NoCCRecp <= 0 Then GoTo end_cc_recp
For x = 1 To NoCCRecp
.Recipients.Add(AddressCC(x)).Type = olCC
Next x
end_cc_recp:
.Subject = vbSubject
.Body = vbMessageText
If NoAttach <= 0 Then GoTo end_attach
For x = 1 To NoAttach
.Attachments.Add AttachFile(x)
Next x
end_attach:
.Send
End With
GoTo Message_Sent_Ok
Message_Sent_Error:
MsgBox "There Was An Error Sending This Message. Please Retry!", vbCritical & vbOKOnly, "Message Error!"
GoTo End_Message
Message_Sent_Ok:
MsgBox "Message Has Been Sent Successfully!", vbOKOnly, "Message Confirmation!"
End_Message:
End Sub
'To add recipient
Public Sub AddRecipient(vbRecipient As String, Optional RecipientType As RecipType)
If vbRecipient = "" Then RecipientType = ToRecip
If RecipientType = 0 Then NoToRecp = NoToRecp + 1
If RecipientType = 1 Then NoCCRecp = NoCCRecp + 1
If RecipientType = 0 Then AddressTo(NoToRecp) = vbRecipient
If RecipientType = 1 Then AddressCC(NoCCRecp) = vbRecipient
Ignore_Add:
End Sub
'To add attachment
Public Sub AddAttachments(vbAttachmentPath As String)
If vbAttachmentPath = "" Then GoTo Ignore_Add
NoAttach = NoAttach + 1
AttachFile(NoAttach) = vbAttachmentPath
Ignore_Add:
End Sub
Private Sub Class_Initialize()
'Reset Recipient and Attachment Variables
NoToRecp = 0
NoCCRecp = 0
NoAttach = 0
'Reset recipient and Attachment Strings
AddressTo(0) = ""
AddressCC(0) = ""
AttachFile(0) = ""
End Sub
---------------------------------------------
____________________________
Funny thought:
Practice makes perfect.....
But nobody's perfect......
so why practice?
|