Send an email via MS Outlook

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
I have some code in VB which allows the user to email a request. When I set this up originally everything worked fine but I have saved this in MS teams. The user now needs to open it up in the Desktop App.

When they do this I get an error at the point of the email code

My code is

Code:
Dim outlookapp As Outlook.Application
Dim outlookmail As Outlook.Mailitem

The error says

Compile error

User-defined type not defined

??

Any ideas ?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Set reference into Outlook library:

Capture.JPG


or use this:

VBA Code:
Dim outlookapp As Object
Dim outlookmail As Object
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmail = outlookapp.CreateItem(0)
 
Upvote 0
Set reference into Outlook library:

View attachment 63243

or use this:

VBA Code:
Dim outlookapp As Object
Dim outlookmail As Object
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmail = outlookapp.CreateItem(0)
Thanks for this, the code change worked but for one part
It errors when it gets to this. when I commented it out, the code ran but didn't send the email

Code:
With outlookmail
     .Bodyformat = olFormatHTML
 
Upvote 0
VBA Code:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
        .TO = "xyz@anc.com"
        .CC = "abc@xyz.com"
        .Subject = "Test"
        .HTMLBody = "<p>Hello world<br>Blah blah blah</p>"
        .Display
    End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,317
Members
449,218
Latest member
Excel Master

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