Results 1 to 8 of 8

Thread: Code to open outlook

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Quote Originally Posted by mml View Post
    Ok I am very literal and VBA illiterate .
    I have changed the code as per advice but nothing , probably , obviously doing something wrong .Outlook not even opening
    Sub Mail_small_Text_Outlook(Recipient As String)
    'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    'Working in Office 2000-2016
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "This is line 1" & vbNewLine & _
                  "This is line 2" & vbNewLine & _
                  "This is line 3" & vbNewLine & _
                  "This is line 4"
        On Error Resume Next
        With OutMail
            .To = "Recipient"
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = strbody
            'You can add a file like this
            '.Attachments.Add ("C:\test.txt")
            .Send   'or use .Display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    I have added a button to the user form named openemail . I would like to have outlook open and have the "To' filed populated by what ever address is in the "email' box

    Advice please
    You've put Recipient in quotes, remove the quotes!

    Did you add?
    Private Sub Openemail_Click()
        Mail_small_Text_Outlook txtMobile
    End Sub
    undergrad detail search 2019 - Ked.xlsm
    Last edited by Aussiebear; 01-18-2025 at 04:49 PM.
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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