Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Buttons/Radio Buttons John Calder New Users to Excel 7 May 16th 08 03:51 AM
Form buttons vs. ActiveX Buttons GeorgeJ Excel Discussion (Misc queries) 3 August 11th 07 09:02 PM
have toggle buttons but everytime print preview buttons move TinSandhu Excel Discussion (Misc queries) 1 October 11th 06 02:57 PM
pivot chart is it possible to hide individual field buttons? Layout Field buttons Matt Charts and Charting in Excel 0 August 27th 06 02:57 PM
Control Buttons vs. Command Buttons Robert Gibson Excel Programming 1 October 13th 03 04:33 PM


All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"