I am trying to generate an email from a button click and have it load data( as the subject line for the email) from the first cell in the row that the button is located in.
Example: In row 22 I place a button in column X and when it is clicked it creates an email using cell A22 as the subject for my email.
I know how to do this by inputting the subject line data directly into the script but, I want to avoid creating hundreds of scripts for the large amount of rows in my spreadsheet.
Here is the manual entry method I currently have:
Private Sub CommandButton1_Click()
Dim outobj, mailobj
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
With mailobj
.To = "xxxxxxxxx@xxxxxxxx.com"
.Subject = "XXXXXXXXXXXX"
.Body = "XXXXXXXXXXXXXXXXXXXXXXX"
.Display
End With
'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
End Sub
I just need the subject to populate from column A in the corresponding button row. I think I need to create another object but I am not sure what the correct code would be and I am not sure how to have the script pull it for ".subject =".
Here is basic data of what I have tried:
► ActiveSheet.Buttons(Application.Caller).TopLeftCell
► "Row of pressed button: " & ActiveSheet.ShapesApplication.Caller).TopLeftCell.Row
► Dim SubjectTo As String
SubjectTo = Cells(XXX,XXX).Value
.subject = SubjectTo
And quite a few other suggestions around the net.
All have worked in their original scripts but I cannot figure out how to incorporate them into what I am trying to do.
I even tried using a Form Shape instead of an ActiveX Button.