VBA error message in Excel when sending e-mails with new Outlook

Torsten_688 31 Reputation points
2023-05-05T14:58:17.3+00:00
Hello Microsoft Team,

When I try to send an e-mail in Excel via VBA using Outlook, I get the error message: "An error has occurred: Object creation not possible through ActiveX component", It works via the Outlook application. If I switch to the New Outlook, the error message appears.

For testing, I used the following coding in Excel:

Sub SendEmail(what_address As String, subject_line As String, mail_body As String) 
    Dim olApp As Object 
    Dim olMail As Object 
    On Error GoTo ErrorHandler 
    Set olApp = GetObject(, "Outlook.Application") 
    If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application") 
    Set olMail = olApp.CreateItem(0) 
    olMail.To = what_address 
    olMail.Subject = subject_line 
    olMail.body = mail_body 
    olMail.Send 
    Exit Sub 

ErrorHandler: 
    MsgBox "An error occurred: " & Err.Description 
End Sub

Thank you and best regards
Torsten
Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,325 questions
Outlook
Outlook
A family of Microsoft email and calendar products.
3,035 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,489 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,525 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Tanay Prasad 2,105 Reputation points
    2023-05-10T07:12:21.0766667+00:00

    Hi @Torsten_688

    This error message can occur if there are issues with the Outlook object model or if there are compatibility issues between Excel and Outlook. Here are a few things you can try:

    1. Make sure that Outlook is installed and that it is the default email program on your computer.
    2. Try repairing your Office installation to ensure that the Outlook object model is installed and working correctly.
    3. Make sure that the version of Outlook you are using is compatible with the version of Excel you are using.
    4. If you are using the New Outlook, try switching back to the Classic Outlook and see if that resolves the issue.
    5. Try updating both Excel and Outlook to the latest versions available.

    Best Regards.

    0 comments No comments