Send out email through command button and macros

Anonymous
2020-06-25T08:46:53+00:00

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:

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

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} vote

11 answers

Sort by: Most helpful
  1. Anonymous
    2020-06-25T08:50:45+00:00

    Hi, I'm Elise, an independent advisor and I'd be happy to help with your issue.

    It looks like you are missing a reference for the Outlook library, can you follow these steps to add:

    In the Visual Basic Editor, on the Tools menu, click References.

    Click to select the Microsoft Outlook 15.0 Object Library check box, and then click OK.

    For reference: https://stackoverflow.com/questions/30598768/ge...

    Kind Regards,

    Elise

    Note: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2020-06-25T09:06:52+00:00

    Hello Elise,

    Thank you so much! However, it seems that my "References" is greyed out for some reason?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2020-06-25T09:10:52+00:00

    If you press the stop button, to stop debugging it will then activate for you.

    Kind Regards,

    Elise

    0 comments No comments
  4. Anonymous
    2020-06-25T09:17:38+00:00

    Thank you!

    I fixed the references issue, but I can see that I already have Microsoft Office 16.0 Object Library checked out

    Any idea what else I can do?

    0 comments No comments
  5. Anonymous
    2020-06-25T09:52:15+00:00

    Can you try replace that line of code with these instead?

    Dim outlookApp As Object
    Dim myMail As Object
    Set outlookApp = CreateObject("Outlook.application")
    Set myMail = outlookApp.CreateItem(0)
    

    Kind Regards,

    Elise

    0 comments No comments