"User-defined type not defined"

sabine

New Member
Joined
Feb 11, 2011
Messages
28
Hello I have inherited some work what includes a workbook that has an email function in it.
The error I get is "User-defined type not defined"

I must be missing something but can not work out how to fix this :confused:


The VB section is

Private Sub cmdEmail_Click()
ThisWorkbook.ActiveSheet.Calculate
ThisWorkbook.Names("Email").RefersToRange.Copy

Dim ol As Outlook.Application

On Error Resume Next
Set ol = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set ol = New Outlook.Application
End If
On Error GoTo 0

Dim m As Outlook.MailItem
Set m = ol.CreateItem(olMailItem)
m.To = ThisWorkbook.Names("EmailName").RefersToRange.Value
m.CC = ThisWorkbook.Names("EmailCc").RefersToRange.Value
m.Subject = ThisWorkbook.Names("EmailSubject").RefersToRange.Value
m.Display


Set ol = Nothing
End Sub

 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You need to look at the Reference in the VBA Screen to see if Outlook has been set.

Use Alt + F11 then go to the Tools Menu and Select References then look to see if Microsoft Outlook (XX) .Object Library has been selected if not then scroll down until you see it and click the box.

Or change to Andrews suggestion.

Dim ol As Object
 
Upvote 0
You may need to set a reference to Outlook. To add a reference to the Microsoft outlook Library

1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Excel version number
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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