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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

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