Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default createing a dynamic array of buttons with captions loaded from she

Yeah, I need to create a pop up box of sorts that has a dynamic array of
buttons who's captions are loaded from a worksheet column.

any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default createing a dynamic array of buttons with captions loaded from she

Well, you could create just an empty UserForm with the VB Editor and use its
_Activate() event to populate it with buttons. The code below shows how that
can be done and how to obtain the captions from a list on a sheet. What it
doesn't show are things like:
making sure the form is tall enough to handle all the buttons - you could
either size it large enough to hold all possible ones or dynamically size it
during the same event.
assigning actions to take when each of the new buttons is clicked on the form.

For what it's worth to you, here's the basic 'seed' code to get you started.

Private Sub UserForm_Activate()
Dim listRange As Range
Dim rowPointer As Integer
Dim ctrlName As String
Dim nextTopPosition As Integer
'change to name of form with list for captions
'and the starting cell on the sheet with the list
Set listRange = Worksheets("Sheet1").Range("A1")
Do While Not IsEmpty(listRange.Offset(rowPointer, 0))
'names will be like:
' cmd_00
' cmd_01
' cmd_02 etc.
ctrlName = "cmd_0" & Trim(Str(rowPointer))
Me.Controls.Add _
"Forms.CommandButton.1", ctrlName, True
Me.Controls(ctrlName).Caption = _
listRange.Offset(rowPointer, 0).Value
With Me.Controls(ctrlName)
.Left = 6
.Top = nextTopPosition + 6
.Width = 120
.Height = 24
End With
'adjust next top position
'based on spacing desired and height set
nextTopPosition = nextTopPosition + 6 + 24
rowPointer = rowPointer + 1
Loop
End Sub


"ouch" wrote:

Yeah, I need to create a pop up box of sorts that has a dynamic array of
buttons who's captions are loaded from a worksheet column.

any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default createing a dynamic array of buttons with captions loaded from

Thanks, I was going to do that but I was hopeingI was missing a command to
create the form programaticaly

"JLatham" wrote:

Well, you could create just an empty UserForm with the VB Editor and use its
_Activate() event to populate it with buttons. The code below shows how that
can be done and how to obtain the captions from a list on a sheet. What it
doesn't show are things like:
making sure the form is tall enough to handle all the buttons - you could
either size it large enough to hold all possible ones or dynamically size it
during the same event.
assigning actions to take when each of the new buttons is clicked on the form.

For what it's worth to you, here's the basic 'seed' code to get you started.

Private Sub UserForm_Activate()
Dim listRange As Range
Dim rowPointer As Integer
Dim ctrlName As String
Dim nextTopPosition As Integer
'change to name of form with list for captions
'and the starting cell on the sheet with the list
Set listRange = Worksheets("Sheet1").Range("A1")
Do While Not IsEmpty(listRange.Offset(rowPointer, 0))
'names will be like:
' cmd_00
' cmd_01
' cmd_02 etc.
ctrlName = "cmd_0" & Trim(Str(rowPointer))
Me.Controls.Add _
"Forms.CommandButton.1", ctrlName, True
Me.Controls(ctrlName).Caption = _
listRange.Offset(rowPointer, 0).Value
With Me.Controls(ctrlName)
.Left = 6
.Top = nextTopPosition + 6
.Width = 120
.Height = 24
End With
'adjust next top position
'based on spacing desired and height set
nextTopPosition = nextTopPosition + 6 + 24
rowPointer = rowPointer + 1
Loop
End Sub


"ouch" wrote:

Yeah, I need to create a pop up box of sorts that has a dynamic array of
buttons who's captions are loaded from a worksheet column.

any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default createing a dynamic array of buttons with captions loaded from

Your reply to my post is empty - is there still a question?

"JLatham" wrote:

Well, you could create just an empty UserForm with the VB Editor and use its
_Activate() event to populate it with buttons. The code below shows how that
can be done and how to obtain the captions from a list on a sheet. What it
doesn't show are things like:
making sure the form is tall enough to handle all the buttons - you could
either size it large enough to hold all possible ones or dynamically size it
during the same event.
assigning actions to take when each of the new buttons is clicked on the form.

For what it's worth to you, here's the basic 'seed' code to get you started.

Private Sub UserForm_Activate()
Dim listRange As Range
Dim rowPointer As Integer
Dim ctrlName As String
Dim nextTopPosition As Integer
'change to name of form with list for captions
'and the starting cell on the sheet with the list
Set listRange = Worksheets("Sheet1").Range("A1")
Do While Not IsEmpty(listRange.Offset(rowPointer, 0))
'names will be like:
' cmd_00
' cmd_01
' cmd_02 etc.
ctrlName = "cmd_0" & Trim(Str(rowPointer))
Me.Controls.Add _
"Forms.CommandButton.1", ctrlName, True
Me.Controls(ctrlName).Caption = _
listRange.Offset(rowPointer, 0).Value
With Me.Controls(ctrlName)
.Left = 6
.Top = nextTopPosition + 6
.Width = 120
.Height = 24
End With
'adjust next top position
'based on spacing desired and height set
nextTopPosition = nextTopPosition + 6 + 24
rowPointer = rowPointer + 1
Loop
End Sub


"ouch" wrote:

Yeah, I need to create a pop up box of sorts that has a dynamic array of
buttons who's captions are loaded from a worksheet column.

any ideas?

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
Cell values as captions TUNGANA KURMA RAJU Excel Discussion (Misc queries) 1 July 24th 06 12:29 PM
createing a list Hot rod Excel Discussion (Misc queries) 2 April 5th 06 08:56 PM
Can the captions for Option Buttons be drawn from other cells ? hedonist68 Excel Discussion (Misc queries) 3 September 8th 05 02:25 PM
Createing a self-sustaining column? Mike Excel Worksheet Functions 1 December 29th 04 03:50 PM
copy macro assigned buttons in an array Phatboy_D Excel Worksheet Functions 1 December 1st 04 10:01 PM


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