VBANEWBIE1229
New Member
- Joined
- Oct 19, 2017
- Messages
- 5
Hi guys,
I am trying to send an email from excel 2013 based on the data in the spreadsheet. I currently have an active button on each row with a macro assigned. This works perfectly, however, I would like to be able to only have one button per sheet that will create the email based on the active selected row. The current code I'm using is below. Thanks in advance for your help!!!!!
Private Sub CommandButton21_Click()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Range("E9")
.CC = Range("F9")
.BCC = ""
.Subject = "SUBJECT TEXT"
.Body = "Hello, " & vbNewLine & vbNewLine & "EMAIL TEXT"
.Attachments.Add (ActiveSheet.Range("C9").Value)
.Display
MsgBox ("Email Created")
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I am trying to send an email from excel 2013 based on the data in the spreadsheet. I currently have an active button on each row with a macro assigned. This works perfectly, however, I would like to be able to only have one button per sheet that will create the email based on the active selected row. The current code I'm using is below. Thanks in advance for your help!!!!!
Private Sub CommandButton21_Click()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Range("E9")
.CC = Range("F9")
.BCC = ""
.Subject = "SUBJECT TEXT"
.Body = "Hello, " & vbNewLine & vbNewLine & "EMAIL TEXT"
.Attachments.Add (ActiveSheet.Range("C9").Value)
.Display
MsgBox ("Email Created")
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub