![]() |
Draw Buttons
Hi... I was wondering if there was any way I could programmaticall draw a button (command or form), setting its size and position in macro -- junx1 ----------------------------------------------------------------------- junx13's Profile: http://www.excelforum.com/member.php...nfo&userid=562 View this thread: http://www.excelforum.com/showthread.php?threadid=26151 |
Draw Buttons
Hi junx13, l can help you a bit.. the code below will draw a button and
then assign a macro to it, Add(484.5, 34.5, 111, 25.5)is the button sizes have a mess round with it... Option Explicit Sub makebutton() ActiveSheet.Buttons.Add(484.5, 34.5, 111, 25.5).Select Selection.OnAction = "assignmacro" End Sub Sub assignmacro() MsgBox "Button Made..." End Sub hth seeya ste |
Draw Buttons
You could even loop through a range of cells:
Option Explicit Sub testme() Dim myRng As Range Dim myCell As Range Dim wks As Worksheet Dim myBTN As Button Set wks = ActiveSheet With wks .Buttons.Delete 'remove existing buttons??? Set myRng = .Range("a1:a10") For Each myCell In myRng.Cells With myCell Set myBTN = .Parent.Buttons.Add(0, 0, 0, 0) myBTN.Height = .Height myBTN.Width = .Width myBTN.Left = .Left myBTN.Top = .Top myBTN.Name = "BTN_" & .Address(0, 0) myBTN.OnAction = ThisWorkbook.Name & "!myBTNmacro" myBTN.Caption = "Click Me" End With Next myCell End With End Sub Sub myBTNMacro() Dim myBTN As Button Set myBTN = ActiveSheet.Buttons(Application.Caller) With myBTN MsgBox .TopLeftCell.Address(0, 0) & vbLf & .Name & vbLf & .Caption End With End Sub junx13 wrote: Hi... I was wondering if there was any way I could programmatically draw a button (command or form), setting its size and position in a macro? -- junx13 ------------------------------------------------------------------------ junx13's Profile: http://www.excelforum.com/member.php...fo&userid=5620 View this thread: http://www.excelforum.com/showthread...hreadid=261510 -- Dave Peterson |
All times are GMT +1. The time now is 06:33 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com