PDA

View Full Version : [SOLVED] Microsoft Object Library Reference Missing - Outlook to Excel



Forex-Forex
05-11-2018, 02:58 AM
Hi Community

I have attached a VBA that works in Excel 2016 but not in Excel/Outlook 2013 that I require.

The purpose is to pull emails from Outlook 2013 to Excel 2013.

When I run it, I am getting an error saying:

Compile Error:
Can't find project or library

Sub Get_Emails (olfdStart As Outlook.MAPIFolder, Date1)

Under References - VBA Project

Missing: Microsoft Outlook 16.0 Object Library.

At work we use Excel and Outlook 2013 and I cannot upgrade to say 2016.

Can any suggest or amend the file attached please as my VBA knowledge is limited.

I have seen some posts on this topic but do not fully understand it.

Any help will be most welcome.

Thanks

Forex-Forex
05-11-2018, 03:30 AM
Someone suggested
changing the code to use late binding, then the version of Outlook being used shouldn't matter and you wouldn't need a reference.

Not sure how to do this. Can someone help?


Option Explicit
Dim n As Long
Sub Get_data()

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim Date1, Date2

Date1 = "01/01/2018"


Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
n = 2
Call Get_Emails(olFolder, Date1)


Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub
Sub Get_Emails(olfdStart As Outlook.MAPIFolder, Date1)
Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olMail As Outlook.MailItem
Dim Recivedt As Date
Dim RMail As Outlook.Items

Set RMail = olfdStart.Items.Restrict("[ReceivedTime] >= """ & Date1 & """")

For Each olObject In RMail 'olfdStart.Items
If TypeName(olObject) = "MailItem" Then

' If olObject.ReceivedTime <= Date1 Then
n = n + 1
Set olMail = olObject
'Sno
Cells(n, 1) = n
'Universal id
Cells(n, 2) = olMail.ConversationID
'Email id
Cells(n, 3) = Get_Sender_Address(olMail) '.SenderEmailAddress

'Date and time workings
Cells(n, 4) = olMail.ReceivedTime

'Size
Cells(n, 6) = olMail.Size

'Subject
Cells(n, 7) = olMail.Subject

' End If
End If
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub

mancubus
05-11-2018, 07:50 AM
CreateObject function

https://www.google.com.tr/search?ei=hK31WtXXGsaSmwWI2oiAAQ&q=excel+vba+createobject+function&oq=excel+vba+createobject+function&gs_l=psy-ab.3..0i22i30k1l2.36844.39378.0.40606.8.8.0.0.0.0.415.1384.3-3j1.4.0....0...1c.1.64.psy-ab..4.4.1383...0i8i13i30k1.0.zDy37HphyUU

Forex-Forex
05-12-2018, 06:50 AM
Many thanks