VBA works in Excel 2013 but not Excel 2010

KungFu Keyboard

New Member
Joined
Oct 22, 2016
Messages
26
Hi there,

The following code works on Excel 2013 but wont work on Excel 2010:
Code:
Sub GetFromOutlook()


Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookRecipient As Outlook.Recipient
Dim OutlookMail As Variant
Dim I As Integer


Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set OutlookRecipient = OutlookNamespace.CreateRecipient("ey@globalloadcontrol.com")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("Irregularity Reports")


I = 1


For Each OutlookMail In Folder.Items
        If OutlookMail.ReceivedTime >= Range("From_date").Value Then
        Range("eMail_subject").Offset(I, 0).Value = OutlookMail.Subject
        Range("eMail_date").Offset(I, 0).Value = OutlookMail.ReceivedTime
        Range("eMail_sender").Offset(I, 0).Value = OutlookMail.SenderName
        Range("eMail_text").Offset(I, 0).Value = OutlookMail.Body
        
        I = I + 1
    End If
Next OutlookMail


Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
Set OutlookRecipient = Nothing

End Sub
I am getting compile errors.

What's the best way around this?

Regards,
Bernard
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Are you sure that you have selected all the correct Library References on the other system?
On the one that it works on, go to VB Editor, and go to Tools -> References, and note all the selected Libraries. Then do the same on the other system, and make sure that similar libraries are selected (the version numbers may be slightly different).

If you still get compile errors, please let us know which lines it indicates are problematic.
 
Upvote 0
You're right - it was a version issue. I had to uncheck the missing object library.15 and check the correct object library.14 for that version of excel

thanks!
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top