When using a VBA code in excel to open outlook. If outlook is already open a new email window opens as it should. If outlook is closed. I get a error. with a notification on the outlook icon. "Another program is using Outlook. To disconnect programs and exit Outlook, click the Outlook icon and then click Exit Now."
I can only proceed if I end outlook through task manager.
I have been using chat GPT etc to try and solve the issue.
This is the first business version of excel I have owned, through switching between personal and business causes the same issue.
The current VBA code I am using is as follows:
Sub SendEmail()
Dim OutlookApp As Object
Dim mItem As Object
Dim Cell As Range
Dim Subj As String
Dim EmailAddr As String
Dim Body As String
Dim cc As String
Dim bcc As String
' Check if Outlook is already running
On Error Resume Next
Set OutlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
' If Outlook is not running, create a new instance
If OutlookApp Is Nothing Then
Set OutlookApp = CreateObject("Outlook.Application")
End If
EmailAddr = Range("B1")
cc = Range("B2")
bcc = Range("B3")
Subj = Range("B4")
Body = Range("B6")
' Create a new mail item
Set mItem = OutlookApp.CreateItem(0)
' Assign values to the mail item properties
With mItem
.To = EmailAddr
.Subject = Subj
.Body = Body
.cc = cc
.bcc = bcc
.Display ' or .Send to send the email
End With
ExitPoint:
Set OutlookApp = Nothing
Set mItem = Nothing
End Sub