Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default email and radio buttons

I have three worksheets in a workbook; using a userform to administer them I
would like to email independantly a sheet (this I understand using SendMail)
BUT I would like the VBA code to look at which radio button has focus and
email the correct sheet.

Any help appreciated, I am essentially a newbie with only basic skills...

Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default email and radio buttons

matt -

use the control toolbox to add the radio button (also called an option
button) on each sheet, it will initially be set as false & will be
entitled "option button 1".
if you double-click on it, it will bring you to something like

Option Explicit

Private Sub OptionButton1_Click()

End Sub

this private sub is in the WORKSHEET module. then you can write your
e-mail sending program in a regular module, say

public sub send_email_now()

blah blah blah (i know NOTHING about e-mail coding!)

end sub


then in the sheet module private sub you would add:


Option Explicit

Private Sub OptionButton1_Click()

Call send_email_now

set optionbutton1.value=false

End Sub

the option button is connected to THAT specific sheet. so whatever
sheet is triggering the option button will send only that sheet (i'm
pretty sure).
then you have to make sure you unselect the option button.

do this for each worksheet......... you will have 3 private sheet
codes & one public regular module code. each sheet code will call the
send_email_now code.
when somebody clicks on the option button, they will HAVE to have that
worksheet open, so you can use activesheet.

hope this helps!
susan




On Mar 20, 8:10 am, Matt T <Matt
wrote:
I have three worksheets in a workbook; using a userform to administer them I
would like to email independantly a sheet (this I understand using SendMail)
BUT I would like the VBA code to look at which radio button has focus and
email the correct sheet.

Any help appreciated, I am essentially a newbie with only basic skills...

Matt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default email and radio buttons

Susan,

thanks for the help. I'm not sure whether I explained correctly.

The option buttons are on a userform with a single email cmd button also.

What I am trying to do is : through selecting an option button then clicking
the email cmd button it will send the sheet associated with the option button
to recipient.

option 1
option 2
option 3

cmdEmail

if option 1
send sheet 1
or if option 2
send sheet 2
or if option 3
send sheet 3

"Susan" wrote:

matt.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default email and radio buttons

On Mar 20, 7:10 am, Matt T <Matt
wrote:
I have three worksheets in a workbook; using a userform to administer them I
would like to email independantly a sheet (this I understand using SendMail)
BUT I would like the VBA code to look at which radio button has focus and
email the correct sheet.

Any help appreciated, I am essentially a newbie with only basic skills...

Matt


Taken from http://www.j-walk.com/ss/excel/tips/tip48.htm
and modified to fit...

Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim ob As OptionButton
Application.ScreenUpdating = False

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

SheetCount = 0

' Add the Option Buttons
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) < 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.OptionButtons.Add 78, TopPos, 150, 16.5
PrintDlg.OptionButtons(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Select Sheet to Email"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount < 0 Then
If PrintDlg.Show Then
For Each ob In PrintDlg.OptionButtons
If ob.Value = xlOn Then
Worksheets(ob.Caption).Copy

' Email code here
Application.Dialogs(xlDialogSendMail).Show
End If
Next ob
End If
Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
' CurrentSheet.Activate
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default email and radio buttons

sorry - i missed the userform part.
sheesh.
susan





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default email and radio buttons

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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default email and radio buttons

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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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 -



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default email and radio buttons

Susan,

Thankyou for your help, firstly.

I had found a way for success, but your code is much more beautiful and
consise than mine. I will try your code and tweak where needed.

Once again thanks, Matt.
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default email and radio buttons

Susan,

I get a Runtime error :438

Do I need to change the Dim (worksheetname) as WorkSheet to reflect the
actual names of each sheet?

Matt.


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default email and radio buttons

yes.........
sorry, i thought that was self-explanatory.
take out the parentheses, as in

Dim Sheet1 as Worksheet

susan


On Mar 21, 10:03 am, Matt T wrote:
Susan,

I get a Runtime error :438

Do I need to change the Dim (worksheetname) as WorkSheet to reflect the
actual names of each sheet?

Matt.



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default email and radio buttons

many thanks
Matt.

p.s. told you I was a newbie, know when it its wrong - can't always see the
answer!

"Susan" wrote:

yes.........
sorry, i thought that was self-explanatory.
take out the parentheses, as in

Dim Sheet1 as Worksheet

susan


On Mar 21, 10:03 am, Matt T wrote:
Susan,

I get a Runtime error :438

Do I need to change the Dim (worksheetname) as WorkSheet to reflect the
actual names of each sheet?

Matt.




  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default email and radio buttons

yes, you're right.......
:D
does it work now????
susan

On Mar 21, 11:05 am, Matt T wrote:
many thanks
Matt.

p.s. told you I was a newbie, know when it its wrong - can't always see the
answer!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Buttons/Radio Buttons John Calder New Users to Excel 7 May 16th 08 03:51 AM
Radio Buttons ceemo[_30_] Excel Programming 2 September 3rd 05 08:15 PM
Radio Buttons nir020 Excel Worksheet Functions 1 December 17th 04 03:23 PM
VBA: Disable Frame and Radio Buttons based on Another Radio Button Being True Mcasteel Excel Worksheet Functions 2 October 29th 04 07:06 PM
Radio Buttons GrahamD Excel Programming 5 December 5th 03 03:45 AM


All times are GMT +1. The time now is 12:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"