Putting 2 command buttons into 1 cell

  • Thread starter Thread starter Roelvdh
  • Start date Start date
R

Roelvdh

Hi,

I can correctly put a command button over a cell, covering half of it.
I want to use the other half for entering a second command button, but the second one can not be added.

</code>
Sheets("Settings").Select
Set rng = ActiveSheet.Range("C10")

Set Obj1 = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False)
With Obj1
.Top = rng.Top
.Width = rng.Width / 2
.Left = rng.Left + .Width
.Height = rng.RowHeight * 2
.Object.Caption = "Return to Program"
End With

Set Obj2 = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.2", _
Link:=False, DisplayAsIcon:=False)
With Obj2
.Top = rng.Top
.Left = rng.Left
.Width = rng.Width / 2
.Height = rng.RowHeight * 2
.Object.Caption = "Recycle"
End With
<code/>

What's wrong?

Roel
 
hi Roel,

Am Sun, 10 Feb 2013 04:33:03 -0800 (PST) schrieb Roelvdh:
I can correctly put a command button over a cell, covering half of it.
I want to use the other half for entering a second command button, but the second one can not be added.

try:

Set Rng = Sheets("Settings").Range("C10")

Set Obj1 =
Sheets("Settings").OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False)
With Obj1
.Top = Rng.Top
.Width = Rng.Width / 2
.Left = Rng.Left
.Height = Rng.RowHeight * 2
.Object.Caption = "Return to Program"
End With

Set Obj2 =
Sheets("Settings").OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False)
With Obj2
.Top = Rng.Top
.Left = Rng.Left + Rng.Width / 2
.Width = Rng.Width / 2
.Height = Rng.RowHeight * 2
.Object.Caption = "Recycle"
End With


Regards
Claus Busch
 
Op zondag 10 februari 2013 13:33:03 UTC+1 schreef Roelvdh het volgende:
Hi,



I can correctly put a command button over a cell, covering half of it.

I want to use the other half for entering a second command button, but the second one can not be added.



</code>

Sheets("Settings").Select

Set rng = ActiveSheet.Range("C10")



Set Obj1 = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _

Link:=False, DisplayAsIcon:=False)

With Obj1

.Top = rng.Top

.Width = rng.Width / 2

.Left = rng.Left + .Width

.Height = rng.RowHeight * 2

.Object.Caption = "Return to Program"

End With



Set Obj2 = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.2", _

Link:=False, DisplayAsIcon:=False)

With Obj2

.Top = rng.Top

.Left = rng.Left

.Width = rng.Width / 2

.Height = rng.RowHeight * 2

.Object.Caption = "Recycle"

End With

<code/>



What's wrong?



Roel

Hi Claus,

Danke vielmals.
So, the numbering of the command buttons is in the order of entry, while I tried to use a new ClassType?
Works like a charm now.

Regards, Roel
 
Back
Top