Hello All,
Does anyone know of a way to update the References to MS Outlook on a VBA Project upon open?
The issue I'm getting is a workbook currently uses MS Outlook to send an email at the end of a procedure, but when a user is on a pc with a different version of MS Outlook (10, the vb script errors when opening and complains about a "Missing MS Outlook Library".
I know it's easy enough to uncheck the Missing Library and check the required one manually - but my users are not that technical and I'd like to handle this error automatically (if its possible?).
Any help would be greatly appreciated.
P.s - I've even tried coding using Late binding - (see below), but I still get the same error (code works perfectly once the correct reference is checked)...!?
Thanks in advance.
Kurt
Sub Sendmail()
Dim objOutlook As Object
Dim objNameSpace As Object
Dim objOlAccount As Object
Dim objMailItem As Object
Dim wcMailAdd As String
wcMailAdd = 'someone@somewhere.com"
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
End If
'Set objOlAccount = objOutlook.Session.Accounts.Item(2)
'Following line is alternative using sender name in lieu of index number
'Set objOlAccount = objOutlook.Session.Accounts.Item("AnEmailAddress@somewhere.com")
'Debug.Print objOlAccount 'For testing - returns required sender
Set objMailItem = objOutlook.CreateItem(0)
With objMailItem
.To = wcMailAdd
.Subject = "Automated Application E-mail - Action Required."
.Body = "Body"
.Attachments.Add ("C:\Temp\W1.pdf")
.Send
End With
Set objMailItem = Nothing
Set objOlAccount = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing
End Sub
Bookmarks