Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a button within a macro

Status
Not open for further replies.
Feb 9, 2003
21
NZ
Hello,

What I need to achieve is as part of an existing macro to create a button whose name is on the control sheet cell A1.

This needs to be placed in an auto-placed way on the csr_coaching sheet. When the button is clicked it needs to go to the sheet named what is in the control!A1 cell

There will be around 10 - 30 of these buttons but the number will vary so I can't specify the location for the button to be placed because of this.

I am running out of ideas how to do this as a whole so any help would be appreciated.

Thanks
 

Hey cameronem,

This macro will automatically create a button for you and place it where you specify. This may not be exactly what you require, but I hope it's a helping start. Just copy and paste the code. Peace!

*****TYHAND
One note: this window may wrap the text of the code, so be sure not to place unnecessary line breaks in it.

Sub CreateMyButton()
'
' this macro creates a button on the current (active worksheet).

Dim intLeft As Integer, intTop As Integer, intWidth As Integer
Dim intHeight As Integer, strCaption
'prompt user for input
intLeft = InputBox("Enter button distance from LEFT edge. 10 may be ok")
intTop = InputBox("Enter button distance from TOP edge. 20 may be ok")
intWidth = InputBox("Enter button WIDTH. 60 may be ok")
intHeight = InputBox("Enter button HEIGHT. 25 may be ok")
strCaption = InputBox("Enter caption for the button")
'create button
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=intLeft, Top:=intTop, Width:=intWidth, Height:=intHeight).Select
ActiveSheet.OLEObjects("CommandButton1").Object.Caption = strCaption
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top