Excel VBA generate email to M365 Outlook

drag1c

Board Regular
Joined
Aug 7, 2019
Messages
108
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi,

I've tried test code below those images, to generate email via M365 Outlook.
So, both Excel and Outlook are in the same package M365 64-bit and this is their interface:
1743507196622.png

1743507223337.png

So, this looks pretty new to me and it's not Web based. This is application installed on my company PC. In past we were using Office 2016 32-bit package.

I have this library activated:
1743507319519.png


And this is my test code:
VBA Code:
Sub TestOutlook()
    Dim objOutlook As Object
    Dim objMail As Object


    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    With objMail
        .To = "your_email@example.com"
        .Subject = "Test Email"
        .body = "This is a test email."
        .display
    End With

    Set objMail = Nothing
    Set objOutlook = Nothing
End Sub

It gives error:
1743507401938.png

Automation error. The specified module could not be found.

Crash happens in this row:
VBA Code:
Set objOutlook = CreateObject("Outlook.Application")

Does anyone have idea what is problem here?
 
In the top right corner of the screen when you have Outlook open, do you have a toggle button that states: 'Try the new Outlook'?
 
Upvote 0
Thanks @Logit, that was the point I was eluding to. I asked about the toggle because on my work computer I have 365 installed but on Outlook, I can switch between old and new with a toggle. I am not sure how long I will have the option though.
 
Upvote 0
This is so sad. So, Microsoft decided to pull out COM object from Outlook.

Is there any other possible way to hook Outlook with VBA?
 
Upvote 0
Not that I know of, you may need to revert back to the old outlook. I have a toggle switch to do this but as I understand, not all installs have this. You may be able to achieve this within the registry but I am not familiar with this method and depending on your setup, it may not be suitable.
 
Upvote 0
Hi all,

I'm very confuse because to me the ui does not look like the "New Outlook". Also why would you still have the COM reference if outlook is not present anymore?

When you go on windows search and type "outlook", do you have one or two results? Also the icons are different.
Picture1.png



I have no idea why it does not work, but i think you have the correct version of Outlook.
 
Upvote 0
Old Outlook is called Classic Outlook and you would need to use that version to run VBA through apps such as Excel.
 
Upvote 0

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