mailto button

Discussion in 'AutoCAD' started by Max, Jun 17, 2004.

  1. Max

    Max Guest

    Hi

    I would like my button when selected to open Outlook and put a email address
    in, similiar to 'mailto' in HTML

    Thanks for the help

    Max
     
    Max, Jun 17, 2004
    #1
  2. Max

    Ben Rand Guest

    Max,

    I just wrote the following for one of my apps.

    Public Sub CreateMessage(sTo As String, sSubject As String, sMessage As
    String, Optional bSend As Boolean)
    Dim oOL As Outlook.Application
    Dim oEmail As Outlook.MailItem

    On Error Resume Next
    Set oOL = GetObject(, "Outlook.Application")
    If oOL Is Nothing Then
    Set oOL = CreateObject("Outlook.Application")
    If oOL Is Nothing Then
    MsgBox "Could not start Outlook. Please start Outlook and try
    again."
    GoSub Cleanup
    End If
    End If

    Set oEmail = oOL.CreateItem(olMailItem)
    With oEmail
    .To = sTo
    .Subject = sSubject
    .Body = sMessage
    .Display

    If bSend = True Then .sEnd
    End With

    Cleanup:
    Set oOL = Nothing
    Set oEmail = Nothing
    End Sub

    You need to add a reference to the Microsoft Outlook X.x (your version)
    Object Library to your project. This was just a first run, but it did
    exactly what I wanted it to do. To hook it up to a button, you'd need to use
    something like:

    ^c^c(vl-vbarun "c:/path/myproject.dvb!CreateMessage");

    Ben Rand
    CAD Manager
    CEntry Constructors & Engineers
     
    Ben Rand, Jun 17, 2004
    #2
  3. Try this - late bind so you don't need to worry about a reference!

    Public Sub CreateMessage(sTo As String, sSubject As String, sMessage As
    String, Optional bSend As Boolean)
    Dim oOL As Object
    Dim oEmail As Object

    On Error Resume Next
    Set oOL = GetObject(, "Outlook.Application")
    If oOL Is Nothing Then
    Set oOL = CreateObject("Outlook.Application")
    If oOL Is Nothing Then
    MsgBox "Could not start Outlook. Please start Outlook and try
    again."
    GoSub Cleanup
    End If
    End If

    Set oEmail = oOL.CreateItem(olMailItem)
    With oEmail
    .To = sTo
    .Subject = sSubject
    .Body = sMessage
    .Display

    If bSend = True Then .sEnd
    End With

    Cleanup:
    Set oOL = Nothing
    Set oEmail = Nothing
    End Sub

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 18, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.