LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Customizing userforms on button clicks

Create a contyrol array for the button.


Insert a cass module and name it clsUserFormEvents

Option Explicit

Public WithEvents mButtonGroup As msforms.CommandButton

Private Sub mButtonGroup_Click()
Select Case mButtonGroup.Caption
Case "CommandButton1" : Userform1.Caption = "Title1"
Case "CommandButton2" : Userform1.Caption = "Title2"
etc.
End Sub


In the userform add

Option Explicit

Dim mcolEvents As Collection

Private Sub UserForm_Initialize()
Dim cBtnEvents As clsUserFormEvents
Dim ctl As msforms.Control

Set mcolEvents = New Collection

For Each ctl In Me.Controls
If TypeName(ctl) = "CommandButton" Then
Set cBtnEvents = New clsUserFormEvents
Set cBtnEvents.mButtonGroup = ctl
mcolEvents.Add cBtnEvents
End If
Next

End Sub


Then

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ps.com...
yes - the buttons are in the userform

On Oct 30, 4:32 pm, Ken Puls wrote:
Hi there,

These are buttons inside the userform? The long way to do it would be
calling a function to evaluate what button was clicked. It's a simple
one liner to change the caption in your Button_Click event:

Me.Caption = "MyCustomTitle"

HTH,

Ken Puls, CMA - Microsoft MVP (Excel)www.excelguru.ca

wrote:
I have a series of buttons all using the same Userform. However, I
would like to be able to personalize the title of the userform -
depending on what button is clicked.


The long way to do it, would be to have a short macro for each button,
that would each generate the userform and accordingly change the
caption details.


But I am assuming there should be a shorter way, to enable a large set
of buttons to use the same userform and be able to personalize the
title as required. Perhaps a series of case statements or even

somthing
simpler??




 
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
Count and Reset Button Clicks Arlen Excel Discussion (Misc queries) 3 May 12th 10 04:33 AM
Button clicks and textbox Exit events Linc Excel Programming 3 December 26th 05 11:23 PM
Open an Outlook folder when a user clicks on a command button ... Rob Keel Excel Discussion (Misc queries) 2 August 1st 05 08:23 AM
Open an Outlook folder when a user clicks on a command button ... Rob Keel Excel Programming 2 August 1st 05 08:23 AM
Why 2 clicks on a command button cush Excel Programming 2 May 10th 05 07:16 PM


All times are GMT +1. The time now is 09:52 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"