I want to send an email via code using Microsoft Visual Basic for Applications. The Microsoft Outlook 12.0 Object Library is checked under Tools/References. The code compiles error-free. The code works fine on two different machines, but when I test it on a third machine, it gives the error when executing line #2.
Dim email As Outlook.MailItem
Set email = Application.CreateItem(olMailItem)
email.To = "[email protected]"
email.Subject = "Subject"
email.Body = "Body"
email.Send
Set email = Nothing
I have reviewed many posts about this error but cannot find a matching solution. Thanks in advance for your help.
Thanks, everyone, for the intial responses. Turns out what solved the problem is to use CDO for sending the email. Here is the code that worked for me: