Putting 2 command buttons into 1 cell

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
 
C

Claus Busch

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
 
R

Roelvdh

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top