View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier[_9_] Jon Peltier[_9_] is offline
external usenet poster
 
Posts: 146
Default creating/manipulating form controls placed on a spreadsheet inexcel using vba

A similar approach to adding the control is AddFormControl:

Sub AddButton()
Dim myButton As Shape
Set myButton = ActiveSheet.Shapes.AddFormControl _
(xlButtonControl, 100, 10, 100, 20)
With myButton
.Name = "My Button"
.TextFrame.Characters.Text = "Click Me"
.OnAction = "MyMacro"
End With
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


Chip Pearson wrote:

The following code will create a command button on the active
sheet and create an event procedure for that command button:

Dim OLEObj As OLEObject
Dim LineNum As Long

Set OLEObj =
ActiveSheet.OLEObjects.Add(classtype:="Forms.Comma ndButton.1")
With OLEObj
.Top = Range("C3").Top
.Left = Range("C3").Left
.Width = Range("C3").Width
.Height = Range("C3").Height
.Name = "MyButton"
With .Object
.Caption = "Click Me"
End With
End With

With ThisWorkbook.VBProject.VBComponents("Sheet1").Code Module
LineNum = .CreateEventProc("Click", "MyButton")
.InsertLines LineNum + 1, "Msgbox ""Hello World"""
End With