#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Create a form button

I'm developing a macro to create buttons and want to feed the process with
variables for placement and size. I'm using this command:

ActiveSheet.Buttons.Add(355, 56, 60, 9).Select

where I'm trying to substitute a variable or variables for the values. When
I do I get an error telling me that this isn't optional. Is there any way to
pass these values through a variable?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Create a form button

I like to position buttons over the cells. So I'll pick out a range and plop
buttons over those cells:

Option Explicit
Sub testme01()
Dim myRng As Range
Dim myCell As Range
Dim myBTN As Button

With ActiveSheet
.Buttons.Delete 'nice for testing
Set myRng = .Range("a1:A5")
For Each myCell In myRng.Cells
With myCell
Set myBTN = .Parent.Buttons.Add(Top:=.Top, _
Height:=.Height, _
Left:=.Left, _
Width:=.Width)
End With
With myBTN
.Name = "BTN_" & .TopLeftCell.Address(0, 0)
.Caption = "Click Me!"
.OnAction = "'" & ThisWorkbook.Name & "'!myMacroHere"
End With
Next myCell
End With
End Sub
Sub mymacrohere()
Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
With myBTN
MsgBox .Name & vbLf & .Caption & vbLf & .TopLeftCell.Address(0, 0)
End With
End Sub

BB Ivan wrote:

I'm developing a macro to create buttons and want to feed the process with
variables for placement and size. I'm using this command:

ActiveSheet.Buttons.Add(355, 56, 60, 9).Select

where I'm trying to substitute a variable or variables for the values. When
I do I get an error telling me that this isn't optional. Is there any way to
pass these values through a variable?

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Create a form button

That's great! Thanks!

"Dave Peterson" wrote:

I like to position buttons over the cells. So I'll pick out a range and plop
buttons over those cells:

Option Explicit
Sub testme01()
Dim myRng As Range
Dim myCell As Range
Dim myBTN As Button

With ActiveSheet
.Buttons.Delete 'nice for testing
Set myRng = .Range("a1:A5")
For Each myCell In myRng.Cells
With myCell
Set myBTN = .Parent.Buttons.Add(Top:=.Top, _
Height:=.Height, _
Left:=.Left, _
Width:=.Width)
End With
With myBTN
.Name = "BTN_" & .TopLeftCell.Address(0, 0)
.Caption = "Click Me!"
.OnAction = "'" & ThisWorkbook.Name & "'!myMacroHere"
End With
Next myCell
End With
End Sub
Sub mymacrohere()
Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
With myBTN
MsgBox .Name & vbLf & .Caption & vbLf & .TopLeftCell.Address(0, 0)
End With
End Sub

BB Ivan wrote:

I'm developing a macro to create buttons and want to feed the process with
variables for placement and size. I'm using this command:

ActiveSheet.Buttons.Add(355, 56, 60, 9).Select

where I'm trying to substitute a variable or variables for the values. When
I do I get an error telling me that this isn't optional. Is there any way to
pass these values through a variable?

Thanks


--

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
Create a form button for email Judge Platt Excel Discussion (Misc queries) 2 November 30th 07 07:36 PM
Button to create a new form ihatetheredskins Excel Worksheet Functions 1 May 3rd 07 07:43 PM
I am trying to create a form in Excel. In my form I want to be abl AngelaD Excel Discussion (Misc queries) 2 January 5th 07 03:16 PM
How to create a form to insert a hyerlink.VBA code to create a for karthi Excel Discussion (Misc queries) 0 July 5th 06 11:26 AM
How do I create a button on the toolbar that will start my form? DMB Excel Discussion (Misc queries) 0 January 8th 06 11:00 PM


All times are GMT +1. The time now is 06:37 PM.

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

About Us

"It's about Microsoft Excel"