Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default get value from combobox on toolbar

Hi,
I have created a combobox on the drawimg toolbar (using code below - copied
from the Excel VBA help file).

How can I find what the selection on it, I would like to know if "First
Item" or "Second Item" is currently selected.


Many thanks,
Dan

Sub Craete_toolbar_Combo()
Set myControl = CommandBars("drawing").Controls _
.Add(Type:=msoControlComboBox, Befo=1)
With myControl
.AddItem Text:="First Item", Index:=1
.AddItem Text:="Second Item", Index:=2
.DropDownLines = 3
.DropDownWidth = 75
.ListHeaderCount = 0
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default get value from combobox on toolbar

I'd use something like:

Option Explicit
Sub Create_toolbar_Combo()
Dim myControl As CommandBarControl
Set myControl = Application.CommandBars("drawing").Controls _
.Add(Type:=msoControlComboBox, Befo=1)
With myControl
.AddItem Text:="First Item", Index:=1
.AddItem Text:="Second Item", Index:=2
.DropDownLines = 3
.DropDownWidth = 75
.ListHeaderCount = 0
.OnAction = "'" & ThisWorkbook.Name & "'!mymacro"
End With
End Sub
Sub mymacro()
With Application.CommandBars.ActionControl
If .ListIndex = 0 Then
MsgBox "Please make a selection"
Exit Sub '???
Else
MsgBox .List(.ListIndex)
End If
End With
End Sub


Dan wrote:

Hi,
I have created a combobox on the drawimg toolbar (using code below - copied
from the Excel VBA help file).

How can I find what the selection on it, I would like to know if "First
Item" or "Second Item" is currently selected.

Many thanks,
Dan

Sub Craete_toolbar_Combo()
Set myControl = CommandBars("drawing").Controls _
.Add(Type:=msoControlComboBox, Befo=1)
With myControl
.AddItem Text:="First Item", Index:=1
.AddItem Text:="Second Item", Index:=2
.DropDownLines = 3
.DropDownWidth = 75
.ListHeaderCount = 0
End With
End Sub


--

Dave Peterson
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
Combobox on Quick Access Toolbar Randy[_2_] Excel Programming 1 September 18th 07 06:16 PM
ComboBox Toolbar Nader[_2_] Excel Discussion (Misc queries) 0 August 13th 07 10:20 AM
ComboBox Toolbar Nader[_2_] Excel Programming 0 August 10th 07 05:59 PM
drop-down / combobox in a custom toolbar Tim Marsh Excel Programming 3 January 29th 07 04:14 PM
combobox from forms toolbar MVM Excel Programming 4 August 2nd 05 09:52 PM


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