email and radio buttons
a few minor glitches now fixed in code below (worked great for me!):
(of course i didn't e-mail the sheet, i just printed it for my
testing).
Option Explicit
Sub userform_initialize()
Dim oControl As Control
For Each oControl In Me.Controls
oControl.Value = False
Next oControl
End Sub
Sub cmdEmail_click()
Dim oControl As Control
Dim (worksheetname) As Worksheet
Dim (worksheetname) As Worksheet
Dim (worksheetname) As Worksheet
Dim sCaption As String
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
For Each oControl In Me.Controls
If TypeName(oControl) = "OptionButton" Then
If oControl.GroupName = "EmailOpt" Then
If oControl.Value = True Then
'it will only choose the one that is selected
sCaption = oControl.Caption
ActiveWorkbook.Worksheets(sCaption).Select
End If
End If
End If
Next oControl
'PUT YOUR E-MAIL CODE HERE
'using the active (selected) sheet
'(which should now be the
'correct sheet since the option
'button name matches the worksheet name.
Unload Me
End Sub
hope it works for you!
susan
On Mar 21, 8:24 am, "Susan" wrote:
matt -
i would handle it differently than okrob, who is a better programmer
than i but who hasn't responded back........... :) but i can help you
with the option buttons being connected to each sheet............
(now, remember i know nothing about the actual e-mailing code!)
in the userform, select all 3 option buttons, & in the properties
window add a group name for all of them (like OptEmail). make each
option button's caption THE EXACT SAME NAME as your 3 worksheets. it
doesn't matter what they are, as long as they match exactly.
sub cmdEmail_click()
dim ocontrol as control
dim Sheet1, Sheet2, Sheet3 as worksheet
dim sCaption as string
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
If Me.oControl.GroupName = "EmailOpt" Then
If oControl.Value = True Then
'it will only choose the one that is selected
sCaption = oControl.Caption
Worksheet(sCaption).select
end if
end if
'PUT YOUR E-MAIL CODE HERE
'using the active (selected) sheet
'(which should now be the
'correct sheet since the option
'button name matches the worksheet name.
unload me
exit sub
i didn't test this - you might have to change around the
If Me.oControl.GroupName line.........
since it's in the userform code you might not need
the "me" designation.
i'm going to go try it out now for myself - i hope it
works for you!
susan
On Mar 20, 1:48 pm, Matt T wrote:
You will have to excuse my 'beginnerness' but I can't see how to have the
cmdEmail button look at which option Button is selected.
Also how do I tie a specific sheet to each of the option buttons.
my programming ability is very basic, but I generally learn from playing
with code, if it is either made obvious where I need to go or with lots of
comments.
Matt- Hide quoted text -
- Show quoted text -
|