MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Change Properties Button In VB???

Posted by KWEETNIE on September 21, 2001 4:21 AM

Does somebody know how to change the properties of a button in VB? For example for button1 "Height=24; Lenght=5425,5; Top=24,75; Wide=72" And for button2 the same except the Top=51! Hope someone can help me?

Posted by Tom Urtis on September 21, 2001 7:15 AM

It sounds like a command button you are looking at. Right click on the button and click Properties, or click the Properties icon (a finger-pointing hand superimposed over a document) from the Control Toolbox toolbar. From there you should be able to adjust the size, color, etc.


Tom Urtis

Posted by NEED HELP!!!! on September 21, 2001 11:41 AM

I know that but do you know how to do this automatically? So I won't have to do it myself all the time but that it will adjust when pressing a button? Thanks!

Posted by Juan Pablo on September 21, 2001 12:00 PM

It's the same, supose you have a button named CommandButton1, in a macro you could do this:

Sub ChangeProp()
With CommandButton1
.Caption = "New Caption"
.Left = .Left + 50
.Top = 1
'And so on...
End With

Juan Pablo


Posted by Tom Urtis on September 21, 2001 12:01 PM

If you need to do this as part of creating a set of buttons from scratch, hopefully this code is what you are looking for; otherwise you've lost me.

ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=128.25, Top:=141, Width:=72, Height:= _

Tom Urtis