Adding Command Button and Formatting It

Guttmann1983

Board Regular
Joined
Jul 27, 2015
Messages
181
Hi - I tried adding a command button and formatting / linking it to a macro but all it is doing is creating the button. Can anyone please point out my error?

Code:
Dim cBut As OLEObjectWith ActiveSheet
Set cBut = .OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
    , DisplayAsIcon:=False, Left:=204.75, Top:=19.5, Width:=142.5, Height _
    :=52.5).Select
End With
With cBut
        .IncrementLeft 9.75
        .IncrementTop -6.75
        .BackColor = &H80000001
        .ForeColor = &H80000004
        .Caption = "Click here to email a copy of this spreadsheet"
        .Font.Size = 10
        .Font.Name = "Arial"
        .TextAlign = fmTextAlignCenter
End With
Range("K4").Select
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUppdating = True
Application.StatusBar = True
Application.DisplayAlerts = True
End Sub


Private Sub CommandButton1_Click()
Mail_workbook_Outlook_2
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is the command button that you created with the first subroutine named CommandButton1? Is the code used to create it in a standard module? Is the commandbutton_click code in the worksheet the button is on or in a standard module?
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top