Send out email through command button and macros

David77

Board Regular
Joined
Jun 24, 2020
Messages
109
Office Version
  1. 365
Platform
  1. Windows
Hello everybody,

First of, please note that I am quite new at VBA coding and thus have extremely limited experience here.

I am currently trying to create an Excel workbook where customers can fill in their orders and "Submit" this to by pressing a button after which the order is sent by email to me.

I was figuring that the best way to do so would be to create a command button linked to a macro. However, this seems to be extremely difficult and I have naturally tried googling this to find solutions. Most of the solutions I found were able to create macros that sent out emails, but not emails that included the excel file as an attachment too.

In order to include the excel file as an attachment, I found the following link: Using Excel VBA to Send Emails with Attachments - wellsr.com which apparently should have solution

However, when I try to run this macro in my own excel file, it comes with the following error:
1593074670741.png


Does anybody here have any idea how I can fix this or provide a better solution to my problem? It would truly be much appreciated!

Thank you so much for your time, whoever may have read this.

Best regards,
David
 
In the code David change the word

VBA Code:
.Display
to
VBA Code:
.Send

Hello Trevor,

Thank you so much!! This is amazing!

Final question, how do I create a command button that does this? Can I somehow link this VBA code to a command button in the sheet?

Best regards,
David
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
On your worksheet go to the Insert Tab and select a shape, more than likely the Rectangle and then point in the spreadsheet where you want it appear. To get a shape to fill the size of the cells hold down the ALT on the keyboard then click and draw with the mouse. Change the colour as necessary and right click on the button you have an option to Edit Text so you can type in what you want it to display. Finally right click the button again and you will see near the bottom Assign Macro, click that option and pick the macro by its name and away you go.
 
Upvote 0
On your worksheet go to the Insert Tab and select a shape, more than likely the Rectangle and then point in the spreadsheet where you want it appear. To get a shape to fill the size of the cells hold down the ALT on the keyboard then click and draw with the mouse. Change the colour as necessary and right click on the button you have an option to Edit Text so you can type in what you want it to display. Finally right click the button again and you will see near the bottom Assign Macro, click that option and pick the macro by its name and away you go.

Amazing!!

Thank you so much Trevor :)

May I ask, is there any way so I can get the Macro to give me a message after you have clicked it, such as: "Your order has been submitted by email. Thank you very much." ?
 
Upvote 0
Add this line below the .Send

VBA Code:
MsgBox "Your order has been submitted by email.", vbInformation, "Sent"
 
Upvote 0
Add this line below the .Send

VBA Code:
MsgBox "Your order has been submitted by email.", vbInformation, "Sent"

Hello Trevor,

Thank you so much. It's perfect!

Is it possible to convert the sheet to a PDF file before I send out the Excel file by mail through the macro?

Best regards,
David
 
Upvote 0
What you need David is inside this thread.

 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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