Results 1 to 3 of 3

Trying to have radio button replace a variable in mail sender code then send

Threaded View

emeeeee Trying to have radio button... 11-17-2015, 10:36 AM
6StringJazzer Re: Trying to have radio... 11-17-2015, 11:43 AM
emeeeee Re: Trying to have radio... 11-17-2015, 03:19 PM
  1. #1
    Registered User
    Join Date
    11-17-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2010
    Posts
    2

    Trying to have radio button replace a variable in mail sender code then send

    Hello All,

    So here is what I am trying to do. I am trying to have different radio buttons send an email to myself with the given code (seen below). I am trying to write a code that will replace the variable "A" with the corresponding option button number. (i.e. if its for optionbutton51, replace A with 51 and then begin the checkmail coding). I've been able to successfully press the radio button and have the mail sent, though it is not replacing the variable A with corresponding button number.

    Just a heads up, I am self teaching myself VBA by reading books in my spare time so I can assist my company run things a little better. If this is a simple fix, apologies for overlooking the simple coding. Below is the code I currently have. I tried previously to use the replace function as well, though it did not work. I also tied to include the option button in the createmail sub and wound up getting 422 emails due to not having a stop.


    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub OptionButton51_Click()
    If OptionButton51.Value = True Then Range("C27").Value = 0
    Dim A As String
    A = "51"                         'Input 51 into A
    CreateMail
    End Sub
    
    Private Sub OptionButton52_Click()
    If OptionButton52.Value = True Then Range("C28").Value = 0
    Dim A As String
    A = "52"
    CreateMail
    End Sub
    
    Sub CreateMail()
    
    Dim A As String
    Dim objOutlook As Object
    Dim objMail As Object
    Dim rngTo As Range
    Dim rngSub As Range
    Dim rngMessage As Range
    Dim rngAttachment As Range
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    
    With ActiveSheet
    
    A = "3"                                             'Just a place holder
    Set rngTo = .Range("M2")
    Set rngSub = .Range("E" & A)              'Trying to call out different cell depending on which radio button pressed
    Set rngMessage = .Range("E" & A)
    
    End With
    
    With objMail
    
    .To = rngTo.Value
    .Subject = rngSub.Value
    .Body = rngMessage.Value
    .Send
    
    End With
    
    Set objOutlook = Nothing
    Set objMail = Nothing
    Set rngTo = Nothing
    Set rngSub = Nothing
    Set rngMessage = Nothing
    Set rngAttachment = Nothing
    
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by emeeeee; 11-17-2015 at 03:20 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code to send mail copying from Excel to a new outlook mail.
    By paz1987 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-11-2015, 07:54 AM
  2. Send Email but make sure they cannot reply to the sender
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2014, 06:51 AM
  3. Inserting a button upon cell value that send an e-mail with saved format
    By 3nduranc3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2013, 07:17 AM
  4. getting sender of the mail which send from Generic Mailbox
    By thirugusto in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 08-17-2012, 10:45 AM
  5. Code to send an e-mail. Don't send if attachment not found
    By thedon_1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2012, 05:41 PM
  6. automatic mail sender and notifier
    By sunny2u86 in forum Excel General
    Replies: 2
    Last Post: 02-02-2012, 02:55 AM
  7. Run code whenever any radio button is clicked
    By rwalk9sr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2007, 06:01 PM

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