Microsoft Visual Basic
Run-time error '-2146959355 (80080005)':
Server execution failed
The above error occurs in Microsoft Office 2019 Excel while running the following code:
Dim OutlookApp As Object, OutlookMail As Object
On Error Resume Next ' Resume execution in case Outlook is already open
Set OutlookApp = GetObject(, "Outlook.Application") ' Try to get the existing instance of Outlook
On Error GoTo 0 ' Reset the error handling
' If Outlook is not open, create a new instance
If OutlookApp Is Nothing Then
Set OutlookApp = CreateObject("Outlook.Application")
End If
' Create a new email
Set OutlookMail = OutlookApp.CreateItem(0)
After troubleshooting with the user attempting to run the code, we determined that there was a new version of Outlook that she was using (which was open), that is different from the original version. Both versions show up on the system, but the new version has "(new)" appended after it. While this new version is open, the above code does not find an Outlook instance and therefore tries to open the old version, which from the error I can only assume will not open if the newer version is already open.
Is there a better way to check for more up-to-date versions of the same application in order to determine if the application is already open before trying to open the application, or a better way to open the application that won't interfere with other open instances of the application? The current workaround was to ensure that the new version of Outlook was not automatically turned on (she had a toggle button for the new version) when she opened Outlook. The VBA works fine while the original version is open, or Outlook is closed but the toggle for the new version isn't on.
The purpose of the code is to automatically create an email that is sent with information from the userform that this code is a part of, namely as a notification system.
Bookmarks