1

Office 365

The VBA in word is used to send an email. The code is used with many computers with success, but for one in particular word freeze at the very beginning of the code when accessing the object model with CreateObject. If Outlook is open it works fine but close it freeze, with the other computers it works fine in both cases.

Dim objOL          As Object
Dim objEmailItem   As Object

Set objOL = CreateObject("outlook.application")      '*** Freezing  ***
Set objEmailItem = objOL.createItem(varOlmailitem)

I tried uninstalling office and reinstalling it, stopping the antivirus, restarting.

Thanks.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
syl.poi
  • 13
  • 2
  • https://stackoverflow.com/questions/31852391/excel-macro-freezes-outlook – braX Dec 19 '21 at 05:47
  • If it's only one computer, then there's a good chance that a complete uninstall and then re-install of Office would need to be done. You can also try to repair it, which is faster. – braX Dec 19 '21 at 10:53
  • Does the `Outlook.exe` still hangs in memory when you try to automate it? Have you tried to check the list of running processes before creating a new Outlook instance? – Eugene Astafiev Dec 19 '21 at 17:30
  • Outlook.exe hangs in memory. it's also visible in the task bar. Note that this is true only for one brand new computer running office365. This process is created by the code and killed with the instruction Set objOL = Nothing. – syl.poi Dec 21 '21 at 14:55

1 Answers1

1

Try to use early binding, you first need to set a reference to the Outlook object library. Use the Reference command on the Visual Basic for Applications (VBA) Tools menu to set a reference to Microsoft Outlook xx.x Object Library, where xx.x represents the version of Outlook that you are working with. You can then use the following syntax to start an Outlook session.

Dim objOL as Outlook.Application 
Set objOL = New Outlook.Application

See Automating Outlook from a Visual Basic Application for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45