Excel VBA Compile error: User-defined type not defined

Anonymous
2019-07-02T11:37:15+00:00

I want the Excel VBA code to automatically send me reminders about contacting clients when next deadline comes

Other things seem to work but it does not send me the mail as intended and give me a Compile Error

Here is the code:

Sub datesexcelvba() <- (and here)

Dim myApp As Outlook.Application <- (problem is here)

Dim mymail As Outlook.MailItem

Dim mydate1 As Date

Dim mydate2 As Long

Dim datetoday1 As Date

Dim datetoday2 As Long

Dim x As Long

lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To lastrow

mydate1 = Cells(x, 12).Value

mydate2 = mydate1

Cells(x, 15).Value = mydate2

datetoday1 = Date

datetoday2 = datetoday1

Cells(x, 16).Value = datetoday

If mydate2 - datetoday2 = 0 Then

Set myApp = New Outlook.Application

Set mymail = myApp.CreateItem(olMailItem)

mymail.To = Cells(x, 11).Value

With mymail

.Subject = "Reminder"

.Body = Cells(x, 20).Text

.Display

'.send

End With

Cells(x, 13) = "Reminder sent"

Cells(x, 13).Interior.ColorIndex = 46

Cells(x, 13).Font.ColorIndex = 2

Cells(x, 13).Font.Bold = True

Cells(x, 14).Value = mydate2 - datetoday2

End If

Next

Set myApp = Nothing

Set mymail = Nothing

End Sub

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} votes

5 answers

Sort by: Most helpful
  1. HansV 462.3K Reputation points MVP Volunteer Moderator
    2019-07-02T11:55:36+00:00

    In the Visual Basic Editor, select Tools > References...

    1. Make sure that there is no reference whose check box is ticked and whose name starts with MISSING. IF there are such, clear their check boxes.
    2. Make sure that the check box of Microsoft Outlook 16.0 Object Library is ticked.
    15 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-07-02T12:09:55+00:00

    I do not clearly understand what is meant under point 1). 

    Microsoft Outlook 16.0 Object Library is ticked. (see attachment below)

    4 people found this answer helpful.
    0 comments No comments
  3. HansV 462.3K Reputation points MVP Volunteer Moderator
    2019-07-02T12:17:19+00:00

    That is the Microsoft Office 16.0 Object Library. Please scroll down the list and tick the check box for Microsoft Outlook 16.0 Object Library.

    PS you use a variable datetoday that has not been declared, nor have you assigned a value to it. Shouldn't that be datetoday1 (or datetoday2)?

    11 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2019-07-02T12:53:07+00:00

    Ahh okay, similar names. My bad. 

    It seems to work now.

    Is it possible to make it run the macro automatically once at 8 pm every day? When computer is in sleep mode but the excel table is still open.

    1 person found this answer helpful.
    0 comments No comments
  5. HansV 462.3K Reputation points MVP Volunteer Moderator
    2019-07-02T12:57:29+00:00

    You'd have to create a scheduled task in Windows that is allowed to wake the computer. I hope someone else can help you with that.

    2 people found this answer helpful.
    0 comments No comments