ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to add control to a worksheet (https://www.excelbanter.com/excel-programming/378721-code-add-control-worksheet.html)

mark kubicki

code to add control to a worksheet
 
I know that:
Set Mycmd = Controls.Add("MSForms.CommandButton.1") ', CommandButton2,
Visible)
will add a control to a form

what would the code be to add a control to a worksheet? (are there any
tricks I will need to do to make it functional (de-activate / activate
worksheet...))

thanks in advance
mark



John Bundy

code to add control to a worksheet
 
When in doubt, record a macro that does what your trying to accomplish, then
edit the code to suit your needs, great way to learn and help you remember
long forgotten functionality. This is what recorded when I added a button.
Can't get much better.

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=79.5, Top:=135.75, Width:=64.5, Height _
:=25.5).Select

-John


"mark kubicki" wrote:

I know that:
Set Mycmd = Controls.Add("MSForms.CommandButton.1") ', CommandButton2,
Visible)
will add a control to a form

what would the code be to add a control to a worksheet? (are there any
tricks I will need to do to make it functional (de-activate / activate
worksheet...))

thanks in advance
mark





All times are GMT +1. The time now is 12:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com