+ Reply to Thread
Results 1 to 2 of 2

Dynamic Button for Email Macro Based on Cell You Click

Hybrid View

  1. #1
    Registered User
    Join Date
    10-27-2023
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    6

    Lightbulb Dynamic Button for Email Macro Based on Cell You Click

    Hi all,

    I have created a macro that generates emails with attachments. It works wonderfully attaching it to a button. BUT, I have about 300 rows in my original workbook, and initially I thought I would have to set 300 buttons per row and attach 300 different macros to them to active.

    What I'm wanting to do, is have one button, that dynamically selects the information for the cell that I am in. So if I click the button then click H6, it selects the info for my .to, .cc etc from row 6. Or backward clicking into the cell first then pressing the button perhaps?

    So, my code is as below you'll see I have the email set to take the .to from A6, .cc from C6, part of the .subject from G6 and the .attachments name from H6. This would then change to A7, C7, G7, H7 etc etc. Each row is different depending on whether there is a 1 or blank in P:BL in my workbook.

    I have attached an example workbook.

    Sub send_EMAIL()
    
    
    Dim OutApp As Object
    Dim Outmail As Object
    Dim Strbody As String
    
    Set OutApp = CreateObject("Outlook.Application")
    Set Outmail = OutApp.CreateItem(0)
    
    Strbody = "<BODY style = font-size:12pt; font-familt:Arial>" & _
    "Hi all, <br><br> blah blah blah this is an example.<br><br>" & _
    "also an example<br><br>" & _
    "Still an example<br><br>" & _
    "Thanks, <br> Joe Bloggs"
    
    
    On Error Resume Next
    With Outmail
    .display
    .to = Sheets("Sheet1").Range("A6").Value
    .CC = Sheets("Sheet1").Range("c6").Value
    .Bcc = ""
    .Subject = "Planogram Update - " & Sheets("Sheet1").Range("g6").Value & " - " & Format(Date, "dd/mm/yy")
    .HTMLBody = Strbody & .HTMLBody
    .Attachments.Add "H:\Example\Example\Example\Example\" & Sheets("All Plans").Range("h6").Value & ".pdf"
    
    End With
    On Error GoTo 0
    
    Set Outmail = Nothing
    
    End Sub
    Thanks in advance wonderful people!
    Last edited by GarnesGambit; 02-23-2024 at 07:39 AM. Reason: SOVLED

  2. #2
    Registered User
    Join Date
    10-27-2023
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    6

    Re: Dynamic Button for Email Macro Based on Cell You Click

    Okay, I have actually solved this myself!

    Where the code has:
    .Range("A6").Value
    
    Replace with
    .Cells(ActiveCell.Row, "A")
    This then means when I click into a cell (for the row which has my unique info) and then click the button, it generates me an email!
    Last edited by AliGW; 02-23-2024 at 07:43 AM. Reason: Code tags added - please review the forum guidelines.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Dynamic option button click?
    By fredep in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-16-2024, 12:33 PM
  2. [SOLVED] Macro to Double Click on Cell in Col E to create Email to attach file
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2023, 06:14 AM
  3. [SOLVED] USERFORM to BITMAP/ or pdf -- to email with a click of a button?
    By Trungii in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2018, 05:26 PM
  4. [SOLVED] Dynamic button on click event
    By MarBoTJ in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2015, 05:13 PM
  5. [SOLVED] Macro to click on button and copy cell context into notepad...?
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2013, 07:27 PM
  6. Click Command Button, run macros based on cell value
    By mc1963 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2012, 04:08 PM
  7. macro help: click button to update value of primary cell
    By uthminister in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2009, 10:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1