+ Reply to Thread
Results 1 to 5 of 5

Code not running on both '07 and '10; references missing on '07

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2012
    Location
    Oxford, England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Code not running on both '07 and '10; references missing on '07

    Hi,

    I have written a project able to generate ppts. based on excel spreadsheet content. In addition I have some code which pulls some user data from Outlook. All the code was written in Office 2010 using Outlook 14.0 object library & Powerpoint 14.0 object library. When the document is opened on an '07 machine, the 'cannot find project or library' error is shown. When I check in the VBA references the two reference libraries I have used to write the code are marked 'MISSING'. After some research, I believe the only answer to my problem is to rewrite the code using late binding rather than early binding. I'm not exactly sure how the syntax would look, & how it differs from what I have. I've included the part of my code that references outlook below.

    Option Explicit
    
    Public username As String
    Public moment As String
    
    'Get current date/time & current user info & store it in given locations
    Sub userfill(userloc As Range, dateloc As Range, timeloc As Range)
    
    Dim shortname As Range
    Dim fullname As Range
    Dim primaryemail As Range
    Dim ext As Range
    Dim objNS As Outlook.Namespace
    Set objNS = Outlook.GetNamespace("MAPI")
    
    'Set ranges
    Set shortname = Sheet10.Range("AZ6")
    Set fullname = Sheet10.Range("AZ7")
    Set primaryemail = Sheet10.Range("AZ8")
    Set ext = Sheet10.Range("AZ9")
    
    'Get data
    username = Application.username
    fullname.Value = objNS.Session.CurrentUser
    primaryemail.Value = objNS.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    ext.Value = Right(objNS.Session.CurrentUser.AddressEntry.GetExchangeUser.BusinessTelephoneNumber, 4)
    'Trim & format shortname
    shortname.Value = Trim(Left(Split(fullname.Value, ",")(1), 2) & ". " & Split(fullname.Value, ",")(0))
    'Trim & format fullname
    fullname.Value = Split(fullname.Value, ",")(1) & " " & Split(fullname.Value, ",")(0)
    fullname.Value = Trim(fullname.Value)
    
    moment = Now
        
    userloc = username
    dateloc = DateValue(moment)
    timeloc = TimeValue(moment)
            
    End Sub
    Many thanks,

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Code not running on both '07 and '10; references missing on '07

    Silly question, Have you tried ticking the checkboxes where it says missing?
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Registered User
    Join Date
    11-08-2012
    Location
    Oxford, England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Code not running on both '07 and '10; references missing on '07

    Those boxes are already ticked, I think excel ticks them automatically when the file loads, and just marks the libraries as 'MISSING'

    Thanks though

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Code not running on both '07 and '10; references missing on '07

    for late binding you need to declare all non-excel objects as simply Object and use CreateObject to initialize them
    Sub userfill(userloc As Range, dateloc As Range, timeloc As Range)
    
       Dim shortname              As Range
       Dim fullname               As Range
       Dim primaryemail           As Range
       Dim ext                    As Range
       Dim objNS                  As Object
       Set objNS = CreateObject("Outlook.Application").GetNamespace("MAPI")
    
       'Set ranges
       Set shortname = Sheet10.Range("AZ6")
       Set fullname = Sheet10.Range("AZ7")
       Set primaryemail = Sheet10.Range("AZ8")
       Set ext = Sheet10.Range("AZ9")
    
       'Get data
       username = Application.username
       fullname.Value = objNS.Session.CurrentUser
       primaryemail.Value = objNS.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
       ext.Value = Right(objNS.Session.CurrentUser.AddressEntry.GetExchangeUser.BusinessTelephoneNumber, 4)
       'Trim & format shortname
       shortname.Value = Trim(Left(Split(fullname.Value, ",")(1), 2) & ". " & Split(fullname.Value, ",")(0))
       'Trim & format fullname
       fullname.Value = Split(fullname.Value, ",")(1) & " " & Split(fullname.Value, ",")(0)
       fullname.Value = Trim(fullname.Value)
    
       moment = Now
    
       userloc = username
       dateloc = DateValue(moment)
       timeloc = TimeValue(moment)
    
    End Sub
    you also need to declare any constants you may use from the other libraries
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    11-08-2012
    Location
    Oxford, England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Code not running on both '07 and '10; references missing on '07

    Thanks very much Joe.

    Works perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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