Another example that looks amazing but uses the password part. I doubt they will ever allow that but i have no idea of the password for a shared mailbox on 365. if there is one - its not something i see - everything just appears to use my microsoft account (sorry not very technical)
Good deal...have you tried DBG's idea regarding the late-binding? I didnt even think about it but I would not be surprised id that turns out to be the culprit.
Even if it doesn't fix this issue, it will pay dividends in the long run because the references you select will have no bearing going forward.
Dim app As Object 'Outlook.Application
Dim msg As Object 'Outlook.MailItem
Dim recipTO As Object 'Outlook.Recipient
Dim recipCC As Object 'Outlook.Recipient
Dim Att As Object 'Outlook.Attachments
olMailItem = 0
Set app = CreateObject("outlook.application")
Set msg = app.CreateItem(olMailItem)
Good deal...have you tried DBG's idea regarding the late-binding? I didnt even think about it but I would not be surprised id that turns out to be the culprit.
Even if it doesn't fix this issue, it will pay dividends in the long run because the references you select will have no bearing going forward.
just did - reckon i have implemented it wrongly....
Code:
Public Sub SendMailboxHTMLMessage(DisplayMsg As Boolean, WhoTo As String, WhoCC As String, Mailbox As String, TheSubject As String, TheBody, Optional AttachmentPath)
Dim objOutlook As Object 'Outlook.Application
Dim objOutlookMsg As Object ' Outlook.MailItem
Dim objOutlookRecip As Object 'Outlook.Recipient
Dim objOutlookAttach As Object 'Outlook.Attachment
Const olMailItem = 0
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
.To = WhoTo
If WhoCC = "" Then GoTo NoCC
' Add the CC recipient(s) to the message.
.CC = WhoCC
NoCC:
' Set the Subject, Body, and Importance of the message.
.Subject = TheSubject
.HTMLBody = TheBody & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
this is a function that i would call a lot where i have been implementing the ideas
Sorry, I made a mistake. You can't declare a constant inside a function. I edited my post above. Or, as @NauticalGent said, move the Const line outside of the procedure.
You can also just replace olMailItem with 0, as in:
ok - still getting the crash out at the .send stage.
here is the current code
Const olMailItem = 0
Code:
Public Sub SendMailboxHTMLMessage(DisplayMsg As Boolean, WhoTo As String, WhoCC As String, Mailbox As String, TheSubject As String, TheBody, Optional AttachmentPath)
Dim objOutlook As Object 'Outlook.Application
Dim objOutlookMsg As Object ' Outlook.MailItem
Dim objOutlookRecip As Object 'Outlook.Recipient
Dim objOutlookAttach As Object 'Outlook.Attachment
'Const olMailItem = 0
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
' Add the To recipient(s) to the message.
.To = WhoTo
If WhoCC = "" Then GoTo NoCC
' Add the CC recipient(s) to the message.
.CC = WhoCC
NoCC:
' Set the Subject, Body, and Importance of the message.
.Subject = TheSubject
.HTMLBody = TheBody & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
'.SentOnBehalfOfName = ""
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
'For Each objOutlookRecip In .Recipients
' objOutlookRecip.Resolve
'Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
When using late binding, any constant needs to be replaced with its integer value. I guessed I missed that one.
I actually helped someone just this weekend having the same issue of moving from using Outlook 2010 to Outlook 365. All I did was removed the reference to Outlook 14.0 library and replaced it with a reference to Outlook 16.0 library. That's basically the first option I posted earlier.
Now, just to check if Outlook is working, you could try using SendObject. If that works, you could try the steps I mentioned above, or we could create a small function to try to send out a simple email, just for testing. Something like:
Code:
Public Function TestOutlook() As Byte
Dim olApp As Object
Dim olMail As Object
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
With olMail
.To = "testaddress@domain.com
.Subject = "TEST"
.Body = "This is a test..."
.Send
End olMail
Set olMail = Nothing
Set olApp = Nothing
End Function
When using late binding, any constant needs to be replaced with its integer value. I guessed I missed that one.
I actually helped someone just this weekend having the same issue of moving from using Outlook 2010 to Outlook 365. All I did was removed the reference to Outlook 14.0 library and replaced it with a reference to Outlook 16.0 library. That's basically the first option I posted earlier.
Now, just to check if Outlook is working, you could try using SendObject. If that works, you could try the steps I mentioned above, or we could create a small function to try to send out a simple email, just for testing. Something like:
Code:
Public Function TestOutlook() As Byte
Dim olApp As Object
Dim olMail As Object
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
With olMail
.To = "testaddress@domain.com
.Subject = "TEST"
.Body = "This is a test..."
.Send
End olMail
Set olMail = Nothing
Set olApp = Nothing
End Function