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!

Simple question...

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
hi

I have a spreadsheet that I want to insert into the e-mail from the code.

What is the way to do that?

Thanks
 
Look toward the bottom of the code you will see a section for Attachments.

Code:
Sub SendMessage(Optional AttachmentPath)
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
  
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")

   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

   With objOutlookMsg
      ' Add the To recipient(s) to the message.
     Set objOutlookRecip = .Recipients.Add("Ian Hayse")
      objOutlookRecip.Type = olTo

      ' Add the CC recipient(s) to the message.
      'Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
      'objOutlookRecip.Type = olCC

      ' Set the Subject, Body, and Importance of the message.
      .Subject = "Subject in email...."
      .Body = "PLDB Reports are done." & vbCrLf & vbCrLf
      .Importance = olImportanceLow  'Low importance

      ' Add attachments to the message.
      'If Not IsMissing(AttachmentPath) Then
        ' Set objOutlookAttach = .Attachments.Add(AttachmentPath)
      'End If

      ' Resolve each Recipient's name.
      For Each objOutlookRecip In .Recipients
         objOutlookRecip.Resolve
         If Not objOutlookRecip.Resolve Then
         objOutlookMsg.Display
      End If
      Next
      .Send

   End With
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top