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

Automatically insert data in the subject field of the of e-mail.

Status
Not open for further replies.

noorani

Programmer
Dec 11, 2002
46
0
0
FR
Is it possible to automatically insert some information in the subject field of the e-mail from the report.

I'm sending the report and i want to show the order number and the client name automatically inserted to the subject of my e-mail from the report,

i'm sending this report using macro and the format of this report is the snapshot.

Please advise me how can i solve this problem thanks in advance.
 
You can use automation like this:
=========
Code:
Public Function MailMessage(Subject As String, Body As String, ToList As Variant, Optional Attachments As Variant) As Boolean

    Dim objOutlook As New Outlook.Application
    Dim Item As Variant
    
    On Error GoTo ErrorOccurred
    
    With objOutlook.CreateItem(olMailItem)
        .Subject = Subject
        .Body = Body
        
        For Each Item In ToList
            .Recipients.Add (CStr(Item))
        Next Item
            
        If Not IsMissing(Attachments) Then
            For Each Item In Attachments
                .Attachments.Add (Cstr(Attachments))
            Next Item
        End If        
        
        .Send 
        
        MailMessage = True
    End With
    
ErrorDone:
    Err.Clear
    Set objOutlook = Nothing
    Exit Function
ErrorOccurred:
    MsgBox Err.Description, vbCritical, cCannotProceedTitle
    MailMessage = False
    Resume ErrorDone
End Function
==========
You would call the function like this:
==========
Code:
Dim sSubject as string
Dim sBody    as string

sSubject="Incoming Report"
sBody="This is the report you required" & vbcrlf _
     & "Please see attachment" & vbcrlf & vbcrlf _
     & "Yours Truly" & vbcrlf 
     & "Rewdee"
if Not MailMessage(sSubject,sBody,array("MyBoss@MyCompany.com"), _
array("c:\MyReport.jpg","C:\MyResume.doc") then
    MsgBox "Report Not sent"
endif
==========
You must make a reference (from the code editor->tools->references) to Outlook for it to work.
Hope this helps,
Rewdee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top