Advertisement
amralomari

VBA Button

Dec 24th, 2018
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Button2_Click()
  2. If ApproveRejectButton = 1 Then
  3.     Dim xOutApp As Object
  4.     Dim xOutMail As Object
  5.     Dim xMailBody As String
  6.     On Error Resume Next
  7.     Set xOutApp = CreateObject("Outlook.Application")
  8.     Set xOutMail = xOutApp.CreateItem(0)
  9.     xMailBody = "Body content" & vbNewLine & vbNewLine & _
  10.               "This is line 1" & vbNewLine & _
  11.               "This is line 2"
  12.                   On Error Resume Next
  13.     With xOutMail
  14.         .To = "Email Address"
  15.         .CC = ""
  16.         .BCC = ""
  17.         .Subject = "Test email send by button clicking"
  18.         .Body = xMailBody
  19.         .Display   'or use .Send
  20.    End With
  21.     On Error GoTo 0
  22.     Set xOutMail = Nothing
  23.     Set xOutApp = Nothing
  24.   ' Approve button code goes here
  25. Else
  26.   ' Reject button code goes here
  27. End If
  28. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement