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
Bookmarks