Results 1 to 3 of 3

Thread: Attachment syntax with outlook mail object

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    13

    Attachment syntax with outlook mail object

    I was wondering if anybody, could tell me the correct syntax to attatch a csv file to an outlook mail object. Do i just have to specify the file path for the outlookmsg.attatchment property?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub SendMessage(DisplayMsg As Boolean, Receiver As String, Optional AttachmentPath)
    2.    
    3.     Dim objOutlook As Outlook.Application
    4.     Dim objOutlookMsg As Outlook.MailItem
    5.     Dim objOutlookRecip As Outlook.Recipient
    6.     Dim objOutlookAttach As Outlook.Attachment
    7.     Dim CallDescription As String
    8.  
    9. ' Create the Outlook session.
    10.     Set objOutlook = CreateObject("Outlook.Application")
    11.  
    12. ' Create the message.
    13.     Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    14.  
    15.     With objOutlookMsg
    16. ' Add the To recipient(s) to the message.
    17.         Set objOutlookRecip = .Recipients.Add(Receiver)
    18.         objOutlookRecip.Type = olTo
    19.  
    20. ' Add the CC recipient(s) to the message.
    21.         Set objOutlookRecip = .Recipients.Add("an other person")
    22.         objOutlookRecip.Type = olCC
    23.  
    24. ' Set the Subject, Body, and Importance of the message.
    25.         .Subject = "Replace this String With your subject Or variable"
    26.         .Body = "replace this String With your subject Or variable"
    27.         .Body = .Body & vbCrLf & "In this manner you can create a body larger than 256 characters"
    28.  
    29. '.Importance = olImportanceHigh  'High importance
    30.  
    31. ' Add attachments to the message.
    32.         If Not IsMissing(AttachmentPath) Then
    33.             Set objOutlookAttach = .Attachments.Add("c:\yourpath\yourfile.csv")
    34.         End If
    35.  
    36. ' Resolve each Recipient's name.
    37.         For Each objOutlookRecip In .Recipients
    38.             objOutlookRecip.Resolve
    39.         Next
    40.  
    41. ' Should we display the message before sending?
    42.         If DisplayMsg Then
    43.             .Display
    44.         Else
    45.             .Send
    46.         End If
    47.  
    48.     End With
    49.  
    50.     Set objOutlook = Nothing
    51. End Sub
    Make sure your project has a reference to the Microsoft Object Library.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    13
    thanking you HACK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width