I am creating a command button on a worksheet after the worksheet is completely populated. The button is supposed to call a UserForm but I keep getting errors. All of the code for this activity is located in Module 1. I tried creating the button two different ways in hopes that this would solve my problem but it didn't. The initial code I tried is commented out.
Here is the code
' ActiveSheet.Buttons.Add(400, 10, 100, 20).Select
' Selection.Characters.Text = "Run This Routine"
' With Selection.Characters(Start:=1, Length:=12).Font
' .Name = "Calibri"
' .FontStyle = "Regular"
' .Size = 11
' .Strikethrough = False
' .Superscript = False
' .Subscript = False
' .OutlineFont = False
' .Shadow = False
' .Underline = xlUnderlineStyleNone
' .ColorIndex = 1
' End With
'
' Routine = ActiveSheet.Name
' ActiveSheet.Shapes.Range(Array("Button 2")).Select
' Selection.OnAction = "ShowRun"
Dim objBtn As Object
Dim ws As Worksheet
Set ws = ActiveSheet
Routine = ActiveSheet.Name
Set objBtn = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", link:=False, _
displayasicon:=False, Left:=400, Top:=10, Width:=100, Height:=20)
objBtn.Name = "BtnRun"
ActiveSheet.OLEObjects(1).Object.Caption = "Run this routine"
Selection.OnAction = "ShowRun"
Worksheets(NewSheet).Range("h1").Select
Worksheets(NewSheet).Protect userinterfaceonly:=True
End Sub
Sub ShowRun()
frmrun.Show
End Sub
Any help is greatly appreciated.
Here is the code
' ActiveSheet.Buttons.Add(400, 10, 100, 20).Select
' Selection.Characters.Text = "Run This Routine"
' With Selection.Characters(Start:=1, Length:=12).Font
' .Name = "Calibri"
' .FontStyle = "Regular"
' .Size = 11
' .Strikethrough = False
' .Superscript = False
' .Subscript = False
' .OutlineFont = False
' .Shadow = False
' .Underline = xlUnderlineStyleNone
' .ColorIndex = 1
' End With
'
' Routine = ActiveSheet.Name
' ActiveSheet.Shapes.Range(Array("Button 2")).Select
' Selection.OnAction = "ShowRun"
Dim objBtn As Object
Dim ws As Worksheet
Set ws = ActiveSheet
Routine = ActiveSheet.Name
Set objBtn = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", link:=False, _
displayasicon:=False, Left:=400, Top:=10, Width:=100, Height:=20)
objBtn.Name = "BtnRun"
ActiveSheet.OLEObjects(1).Object.Caption = "Run this routine"
Selection.OnAction = "ShowRun"
Worksheets(NewSheet).Range("h1").Select
Worksheets(NewSheet).Protect userinterfaceonly:=True
End Sub
Sub ShowRun()
frmrun.Show
End Sub
Any help is greatly appreciated.