VBA to send email

danbates77

New Member
Joined
Jan 10, 2017
Messages
36
Office Version
  1. 2016
Hi,

I am not sure what I'm about to ask is possible but let's see.

I want to be able to send an email via VBA but it can't be through the following code because it doesn't work on my works PC.

VBA Code:
Sub Email()
    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    With OutMail
        .to = ""
        .to = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .Body = ""
        .Attachments.Add 
        
        ' You can add other files by uncommenting the following line.
        '.Attachments.Add ("C:\test.txt")
        ' In place of the following statement, you can use ".Display" to
        ' display the mail.
        .Send
    End With
    On Error GoTo 0
    MsgBox "File sent successfully"
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

I have this code that opens up my email and I was wondering if it could be merged into a code, so it does the same as the code above,but works on my works PC.

VBA Code:
Sub EmailNew()
Shell "C:\Windows\explorer.exe C:\Users\Public\Desktop\Microsoft Outlook Web Access.url"
End Sub

Any help would be appreciated
Thanks
Dan
 

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.
You can't use VBA to send emails because Outlook Web Access (OWA) doesn't have an Object library for Excel; using VBA requires desktop Outlook.
 
Upvote 0
Solution
You may be able to have Power Automate send emails based on the data in your workbook.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,691
Members
449,117
Latest member
Aaagu

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