Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combo Boxes built with Control Toolbox on a Worksheet

I would appreciate help on the following. The gist of my problem is that if I
draw a combo from the control toolbox using the mouse everything is fine.
But if I record a macro to do this and then use that macro in the future to
build the combo on user demand I am unable to address the combo from other
VBA code. I enclose the code below.

Option Explicit
Private Sub BuildOneRotaCmd_Click()
'Command Button to trigger filling and or building of the Combo box GPCombo
'I have commented out the lines which cause failure.
'So the line below oleobjects.add is the one cretaing the basic problem

'ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comb oBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=124.8, Top:=91.2, Width:=83.4, Height:= _
17.4).Select
'Selection.Name = "GPCombo"
Range("a1").Select
ActiveWorkbook.Save
FillTheCombo
End Sub
Private Sub FillTheCombo()
Dim counter As Integer
Sheets("welcome").Select
With GPCombo 'Fails here if Combo box built by code above with message
Variable undefined
'With ActiveSheet.OLEObjects("GPCombo") 'If I replace the above "With" with _
this line it works but fails on the
Additem _
message "Object doesn't support this
property or method

For counter = 10 To 25
.AddItem Sheets("Rota").Cells(counter, 10)
Next counter
End With

End Sub
Private Sub GPCombo_Click()
'GPCode is a Public varaible
GPcode = GPCombo.Value
MsgBox GPcode

If Sheets("sheet2").Range("a3") = GPcode Then
MsgBox "Thats good it matches the selection"
End If
End Sub
--
Alan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Combo Boxes built with Control Toolbox on a Worksheet

ALan,

This works for me

Dim GPCombo As Object
Set GPCombo = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1",
_
Left:=124.8, Top:=91.2, Width:=83.4, Height:=17.4)
GPCombo.Name = "GPCombo"
With GPCombo.Object
.AddItem "Bob"
.AddItem "Lynne"
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alan" wrote in message
...
I would appreciate help on the following. The gist of my problem is that

if I
draw a combo from the control toolbox using the mouse everything is fine.
But if I record a macro to do this and then use that macro in the future

to
build the combo on user demand I am unable to address the combo from other
VBA code. I enclose the code below.

Option Explicit
Private Sub BuildOneRotaCmd_Click()
'Command Button to trigger filling and or building of the Combo box

GPCombo
'I have commented out the lines which cause failure.
'So the line below oleobjects.add is the one cretaing the basic problem

'ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comb oBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=124.8, Top:=91.2, Width:=83.4,

Height:= _
17.4).Select
'Selection.Name = "GPCombo"
Range("a1").Select
ActiveWorkbook.Save
FillTheCombo
End Sub
Private Sub FillTheCombo()
Dim counter As Integer
Sheets("welcome").Select
With GPCombo 'Fails here if Combo box built by code above with message
Variable undefined
'With ActiveSheet.OLEObjects("GPCombo") 'If I replace the above "With"

with _
this line it works but fails on

the
Additem _
message "Object doesn't support

this
property or method

For counter = 10 To 25
.AddItem Sheets("Rota").Cells(counter, 10)
Next counter
End With

End Sub
Private Sub GPCombo_Click()
'GPCode is a Public varaible
GPcode = GPCombo.Value
MsgBox GPcode

If Sheets("sheet2").Range("a3") = GPcode Then
MsgBox "Thats good it matches the selection"
End If
End Sub
--
Alan



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
what is code to activate a combo box in control toolbox Pogo Excel Discussion (Misc queries) 1 July 23rd 06 10:41 AM
combo box from control toolbox Hassan Merzha Excel Discussion (Misc queries) 1 June 16th 06 12:24 PM
control toolbox combo box sbhayes Excel Discussion (Misc queries) 0 February 15th 06 12:45 AM
combo box of control toolbox filo666 Excel Programming 2 April 19th 05 05:35 AM
Mystery of the moving control toolbox combo box? Don Wiss Excel Programming 2 December 26th 04 11:16 PM


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