+ Reply to Thread
Results 1 to 3 of 3

Late binded VBA Code working in Excel 2013 but not Excel 2010

  1. #1
    Registered User
    Join Date
    11-10-2015
    Location
    UK london
    MS-Off Ver
    Excel
    Posts
    2

    Late binded VBA Code working in Excel 2013 but not Excel 2010

    The following late binded code works in Excel 2013 but doesn't work in Excel 2010. I think I may have late binded it wrong. Essentially, the code pulls e-mail dates and sender e-mail address from Outlook and populates it in Excel.



    Here's my attempt at late binding this piece of code:

    Early bound version

    Dim olApp As Outlook.Application
    Dim olNs As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim olMail As Outlook.MailItem
    Dim eFolder As Outlook.Folder
    Dim i As Long
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim iCounter As Long
    Dim lrow As Long

    Set wb = ActiveWorkbook
    Set ws = wb.Worksheets("vlookup")

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")

    wb.Sheets("vlookup").Range("A2:C500").ClearContents

    'i think you want column E here, not L?
    lastRow = ThisWorkbook.Worksheets("vlookup").Cells(Rows.Count, "E").End(xlUp).Row

    For Each eFolder In olNs.GetDefaultFolder(olFolderInbox).Folders
    Set olFolder = olNs.GetDefaultFolder(olFolderInbox)
    For i = olFolder.Items.Count To 1 Step -1

    If TypeOf olFolder.Items(i) Is MailItem Then
    Set olMail = olFolder.Items(i)
    For iCounter = 2 To lastRow
    If InStr(olMail.SenderEmailAddress, ws.Cells(iCounter, 5).Value) > 0 Then 'qualify the cell
    With ws
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("C" & lrow + 1).Value = olMail.Body
    .Range("B" & lrow + 1).Value = olMail.ReceivedTime
    .Range("A" & lrow + 1).Value = olMail.SenderEmailAddress
    End With
    End If
    Next iCounter
    End If
    Next i
    Set olFolder = Nothing
    Next eFolder


    End Sub
    From what I've scoured from the net, the following are the only changes I need to make.

    Late bound version

    Dim olApp As Object
    Dim olNs As Object
    Dim olFolder As Object
    Dim olMail As Object
    Dim eFolder As Object
    Dim i As Long
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim iCounter As Long
    Dim lrow As Long

    Set wb = ActiveWorkbook
    Set ws = wb.Worksheets("vlookup")


    Set olApp = CreateObject("Outlook.Application")
    Set olNs = olApp.GetNamespace("MAPI")
    My problem:

    It runs on my Excel 2013 but doesn't work on Excel 2010. There's no code error, but Nothing populates.

    I've gone into Tools --> References, unclicked the MISSING 15.0 objects and clicked 14.0 Objects library for Excel/Outlook/Office, and when I run it there's no errors or anything BUT nothing happens

    ANy help is greatly appreciated, thanks!

  2. #2
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: Late binded VBA Code working in Excel 2013 but not Excel 2010

    Why do you prefer late bound? Early bound is always better/faster in my experience...?

    I don't see where you set efolder ofolder, and omail variable object types. Not sure if that has something to do with it not running in 2010?
    Last edited by Obsessed; 11-10-2015 at 06:04 PM.
    Want to show appreciation for the help you received from a member? Give them reps by clicking the bottom left of their post!

  3. #3
    Registered User
    Join Date
    11-10-2015
    Location
    UK london
    MS-Off Ver
    Excel
    Posts
    2

    Re: Late binded VBA Code working in Excel 2013 but not Excel 2010

    The early bound version gives me object not defined error, because it shows a MISSING outlook objects library 15.0

    I don't see where you set efolder ofolder, and omail variable object types. Not sure if that has something to do with it not running in 2010?
    But it populates nonetheless on my Excel 2013
    Last edited by daruki; 11-10-2015 at 06:05 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macros 2010 Not working in Excel 2013
    By waqarqrl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2015, 03:57 AM
  2. VBA formatting macro that worked in Excel 2010 is not working correctly in Excel 2013
    By jayar2112 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2015, 01:14 PM
  3. VBA working in Excel 2013 but not 2010
    By sb2323 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2015, 07:26 AM
  4. Macro code working fine in excel 2013 but not in excel 2010.
    By sere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2014, 02:23 AM
  5. Spreadsheet macros working in Excel 2010 but not in Excel 2013
    By boatbabe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2014, 12:03 PM
  6. VBA Working in Excel 2010 and not 2013
    By Jason*** in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2014, 11:28 AM
  7. [SOLVED] Excel 2010 to Excel 2013 Eroor? PivotTable, ListBox VBA not working.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2014, 07:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1