I have never used macro's before or used Visual Basic for Applications. I need this as part of a checklist in Microsoft Excel 2013.
My Aim: Once the checklist has been filled, I want the active worksheet to be attached to an email whilst auto-filling the email addresses and the subject which will be "Checklist_XXX" the XXX part for example will be amended depending on who is using the checklist, so it could be Checklist_12345.
Steps I have taken: The checklist is complete, and I have created a ActiveX button which by default has no code.
I found the following code online which seems to be what I need:
Sub Mail_workbook_Outlook_1() Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .to = "[email protected],[email protected]" .Subject = "Checklist_" .Body = "I have attached my checklist related to change" .Attachments.Add ActiveWorkbook.FullName .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub What I think this does: I believe it will create an Outlook email with the attached message and will have [email protected] and [email protected] as recipients with the subject and body amended. I changed it from .send to .display so I can review before I send.
The short question: How do I run this code on a click within my Excel spreadsheet, preferably via a button?