Command Button VBA Problem

Ryan H ARENA

New Member
Joined
Jun 16, 2018
Messages
5
I'm attempting to create a command button that will send the current sheet to someone as an email, but when I click the button nothing happens. Here is the code, and I'm not sure if I assigned it properly. Excel 2010. Thanks for the help.

Sub Send_Range()
ActiveSheet.Range("A1:P1000").Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = "Daily Production Goal spreadsheet"
.Item.To = "aaa.bbb@ccc"
.Item.Subject = "Today's Production Goal"
.Item.Send
End With
End Sub
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi & welcome to the board.
Firstly, I removed your email address from your post, as Spam Bots routinely troll Public User Forums like these looking for email addresses to Spam.
Secondly what type of command button are you using?
 
Upvote 0
Just a heads up that email was a fake I made up. The command button I'm using is an ActiveX Control Button. I just want the user of the spreadsheet to be able to click the button or on a cell or something and then it'll email the current spreadsheet to whoever is specified in the code
 
Upvote 0
On the developer tab select Design mode, then double click the button.The VBE will open up & you'll see something like
Code:
Private Sub CommandButton1_Click()

End Sub
Simply copy your code & paste it between those 2 lines
 
Upvote 0
It's giving me a compile error that says expected end sub when I paste the code between those lines.

Code:
Private Sub CommandButton1_Click()
Sub Send_Range()
 ActiveSheet.Range("A1:P1000").Select
 ActiveWorkbook.EnvelopeVisible = True
 With ActiveSheet.MailEnvelope
 .Introduction = "Daily Production Goal spreadsheet"
 .Item.To = "aaa.bbb@ccc"
 .Item.Subject = "Today's Production Goal"
 .Item.Send
 End With
 End Sub
End Sub
 
Last edited by a moderator:
Upvote 0
Remove these 2 lines
Code:
Private Sub CommandButton1_Click()
[COLOR=#ff0000]Sub Send_Range()[/COLOR]
 ActiveSheet.Range("A1:P1000").Select
 ActiveWorkbook.EnvelopeVisible = True
 With ActiveSheet.MailEnvelope
 .Introduction = "Daily Production Goal spreadsheet"
 .Item.To = "aaa.bbb@ccc"
 .Item.Subject = "Today's Production Goal"
 .Item.Send
 End With
 [COLOR=#ff0000]End Sub[/COLOR]
End Sub
 
Upvote 0
It turns that the initial code I had isn't quite what I'm looking for. Is there a way I can attach the current worksheet as an attachment, because I'd like the recipient to be able to open only the current sheet. The way it is now it sends the selected cells as an image and it can't be opened in excel.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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