borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How can i check if a PC is online in a network?)Next Topic (Abort Shut Down on a PC) New Topic New Poll Post Reply
AndreaVB Forum : Network : Sending Excel,Word File by e-mail
Poster Message
dmedina
Level: Guest


icon Sending Excel,Word File by e-mail

I work for a company that e-mail has turn out to be the easy way to exchange information. This info is done in excel or word. What I would like to do is add a button that launches a module that will load the current form into an e-mailer and send it to one or more persons.  

16-10-2002 at 07:51 PM
| Quote Reply
noycez
Level: VB Guru


Registered: 14-10-2002
Posts: 79
icon 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?

17-10-2002 at 01:21 AM
View Profile Send Email to User Show All Posts | Quote Reply
dmedina
Level: Guest

icon Re: Sending Excel,Word File by e-mail

Thanks this gives me a place to start.

18-10-2002 at 01:00 AM
| Quote Reply
ErrorNow
Level: Guest

icon Re: Sending Excel,Word File by e-mail

would that work for vb6 and vb net?

26-07-2003 at 06:12 AM
| Quote Reply
AndreaVB Forum : Network : Sending Excel,Word File by e-mail
Previous Topic (How can i check if a PC is online in a network?)Next Topic (Abort Shut Down on a PC) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder