CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2000
    Posts
    58

    Outlook - Easy one

    Hi,

    If I have outlook open, does anyone know how to load a new message window from vb.

    Thanks in advance.


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Outlook - Easy one

    <de-lurk>

    If you have the full version of Outlook (not Outlook Express), you can use the object model to do just about anything for you :

    This sample shows how to use Outlook to create and send a new message (including an attachment) :


    '
    Sub SendMessage(DisplayMsg as Boolean, Receiver as string, optional
    AttachmentPath)
    Dim objOutlook as Outlook.Application
    Dim objOutlookMsg as Outlook.MailItem
    Dim objOutlookRecip as Outlook.Recipient
    Dim objOutlookAttach as Outlook.Attachment
    Dim CallDescription as string
    '
    ' 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(Receiver)
    objOutlookRecip.Type = olTo
    '
    ' Add the CC recipient(s) to the message.
    '
    set objOutlookRecip = .Recipients.Add("an other person")
    objOutlookRecip.Type = olCC
    '
    ' set the Subject, Body, and Importance of the message.
    '
    .Subject = "Replace this string With your subject Or variable"
    '
    .Body = "replace this string With your subject Or variable"
    .Body = .Body & vbCrLf & "In this manner you can create a body larger than 256 characters"
    '
    .Importance = olImportanceHigh 'High 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
    next
    '
    ' Should we display the message before sending?
    '
    If DisplayMsg then
    .Display
    else
    .Send
    End If

    End With
    '
    set objOutlook = nothing
    End Sub




    If you simply want to bring up a form for the user to type in all the details, the following will suffice :


    Dim oOutlook as Outlook.Application
    Dim oMsg as Outlook.MailItem

    set oOutlook = GetObject(, "Outlook.Application")
    set oMsg = oOutlook.CreateItem(olMailItem)
    '
    oMsg.Display vbModal
    '
    set oMsg = nothing
    set oOutlook = nothing




    </de-lurk>



    Chris Eastwood
    VBCodeLibrary - http://www.vbcodelibrary.com

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

Featured