I am usinig the code below to create a new instance of Outlook and an email message with an attachment and send it. I have also implemented the use of "ClickYes" to fully automate the process. All of this works exacly as expected when I run it here. I have tested it with Outlook open and with it closed and the code works as expected.
However, when my client attempts to use this same code an error is reported if Outlook is not open. If Outlook is open it seems to work as designed. This code is supposed to create a new instance of the Outlook object, use that object to create the new email and when the email is send, kill that instance of Outlook.
References have been set and checked with no "missing" ones found and no other code type errors occuring.
I am wondering if ther can be some setting on the client's machine that may be causing this.
Any thoughts are welcome and appreciated.
Thanks, in advance.
However, when my client attempts to use this same code an error is reported if Outlook is not open. If Outlook is open it seems to work as designed. This code is supposed to create a new instance of the Outlook object, use that object to create the new email and when the email is send, kill that instance of Outlook.
Sub SendEmailMessage(strEmailAddress As String, _
strEmailCCAddress As String, _
strEmailBccAddress As String, _
strSubject As String, _
strMessage As String, _
blnDisplayMessage As Boolean, _
Optional strAttachmentFullPath As String)
On Error GoTo ErrorMsgs
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application 'GetObject(,"Outlook.Application")
Dim email As Outlook.MailItem
Set email = olApp.CreateItem(olMailItem)
email.Recipients.Add strEmailAddress
email.Subject = strSubject
email.Body = strMessage
email.Attachments.Add strAttachmentFullPath
If blnDisplayMessage = True Then
email.Display
Else
'* Send message by putting it in the Outbox
email.Send
End If
ExitHere:
Set email = Nothing
Set olApp = Nothing
Exit Sub
ErrorMsgs:
MsgBox Err.NUMBER, Err.Description
GoTo ExitHere
End Sub
References have been set and checked with no "missing" ones found and no other code type errors occuring.
I am wondering if ther can be some setting on the client's machine that may be causing this.
Any thoughts are welcome and appreciated.
Thanks, in advance.