Results 1 to 4 of 4
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    add refrences by VBA

    Hi All

    is it possible to add via vba the references for outlook, excel and word based in the version that the end user has installed??

    i have an application that I'm working on for work that uses early binding and I'm distributing it to all the end users, we have various versions of office here from
    2007 - 2013

    this application is split so i just need to distribute the front end, but i don't want to create separate front ends with the correct references in, is it possible that vba could add the correct reference based on the version of office that is installed on the end users pc's?



    it may be better for me to convert all the code to late binding, but i have been trying to do so for the last few days with out any success.

    an example of the code i am having problems is below, "this is the most basic" that the application has it opens outlook and adds the customer e-mail address in the "To field" this works with early binding, when i remove the reference nothing happens when clicking the "Send_E_Mail_To_Client" button the application compiles with no errors outlook never opens.

    all the other code is based on this although more complicated, but it seems im struggling with the basics

    Private Sub Send_E_Mail_To_Client_Click()

    Dim OlApp As Object
    Dim objMail As Object
    On Error Resume Next 'Keep going if there is an error
    Set OlApp = GetObject(, "Outlook.Application") 'See if Outlook is open
    If Err.Number = 429 Then 'Outlook is not open
    Set OlApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
    End If
    On Error GoTo 0
    'Create e-mail item
    Set objMail = OlApp.CreateItem(olMailItem)


    With objMail
    'Set body format to HTML
    .BodyFormat = olFormatHTML
    .To = Me.E_Mail
    .Subject = ""
    .HTMLBody = "Dear" & " " & Me.Full_Name.Value
    .Display

    End With
    Set OlApp = Nothing
    Set objMail = Nothing
    End Sub

    my coding skills are still very much in the early stages, i like to use early binding as it provides intellisence but if late binding is the way to go then any help in this area would be most welcome.

    Steve

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi RuralGuy

    Thats great many thanks

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You're welcome. I hope they help.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums