• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA

A019

New Member
Hi

How do I make a macro that sends an automatic email from Outlook when I click a button in Excel?

Also, how can I use VBA to protect certain cells so that users can’t edit them, but leave the rest of the sheet open?

Thanks
 
>>> use code - tags <<<
Code:
Sub SendEmail()
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim MailBody As String

    ' Create Outlook application
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0) ' olMailItem = 0

    ' Define your message
    MailBody = "Hello," & vbNewLine & vbNewLine & _
               "This is an automated email from Excel." & vbNewLine & _
               "Regards," & vbNewLine & "Your Name"

    With OutlookMail
        .To = "recipient@example.com"
        .CC = ""
        .BCC = ""
        .Subject = "Automated Email from Excel"
        .Body = MailBody
        ' You can also use .HTMLBody if you prefer HTML format
        '.Attachments.Add "C:\Path\To\File.xlsx" ' Optional
        .Sen
 
Last edited by a moderator:
Back
Top