Started Receiving "Compile Error: User-defined Type Not Defined" when trying to email

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have some code that would send an email for me. But after having Outlook updated or reinstalled, now it no longer works on this particular computer (though this code does work on another computer).

VBA Code:
Sub DQ_Comp()
    [COLOR=rgb(184, 49, 47)][B]Dim OutApp As Outlook.Application[/B][/COLOR], OutMail As Outlook.MailItem, OutAccount As Outlook.Account, strbody As String
    Set OutApp = CreateObject("Outlook.Application"): Set OutMail = OutApp.CreateItem(olMailItem)
    'specify which email account
    Set OutAccount = OutApp.Session.Accounts.Item("anichols@somewhere.com") 
    strbody = "Test Email" & vbNewLine & _
              "Drew Nichols"
    On Error Resume Next
    With OutMail
        .To = "anichols@somewhere.com"
        .Subject = "Delinquency Report Complete"
        .Importance = 2
        .Body = strbody
        .SendUsingAccount = OutAccount
        '.Attachments.Add Sheets(1).Range("B38").Value '41
        .Send
    End With
    On Error GoTo 0: Set OutMail = Nothing: Set OutApp = Nothing: Set OutAccount = Nothing
End Sub
The red is what gets highlighted. My online Research suggested adding Microsoft Scripting Runtime to the VBA references, but that did not help either. I've tried to look through outlook to see what the issue is, but my account looks just the same as it did before.
I'm not sure if other people have encountered this, or if they know of any creative solutions to get this to function again, but any help would be greatly appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You need to add a reference to Microsoft Outlook 16.0 Object Library
 
Upvote 0
Solution
??? OMG! So simple, and that completely solved it. Sometimes the simplest things can solve the most frustrating issues.

Thank you so much!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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