none
Microsoft Object Library in VBA RRS feed

  • Question

  • I am creating a form in Word. My version of Office is 2010. I would like for this form to be on our website for many users to be able to use. (I will require that they have Word and Outlook, but cannot predict what version they have.) On this form, I have a Submit button that runs a macro to send the completed form via Outlook Email (as an attachment) to a given email address. 

    It runs fine on my machine. However, when I send it to my coworker who has Office 2007, the Outlook Object Library is not available, so it dies unable to find olMailItem. I cannot check the Object Library 12.0 in VB Editor, because I have 14.0. I would like for this to run simply. 

    Is there a way in my Word VBA Macro to make the Outlook Object Library available to this Macro? I will include my code for you to get a better idea of what I'm doing. 

    If I cannot open the object library through the macro, do you have a suggestion on how to accomplish this? 

    Thank you!!

    Sheron

    The Macro: 

    Private Sub CommandButton1_Click()

    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document
     
    On Error Resume Next

    Application.ScreenUpdating = False
    Set OL = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set OL = CreateObject("Outlook.Application")
    End If

    Set EmailItem = OL.CreateItem(olMailItem)

    Set Doc = ActiveDocument
    Doc.Save
     
    With EmailItem
        .Subject = "Go Grant Application"
        .Body = "Please see the attached Go Grant Application." & vbCrLf & _
        "This will be the next line in the message." & vbCrLf & _
        "This will be the last line in the message."
        .To = "sheronw@nhcconline.com"
        .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
        .Attachments.Add Doc.FullName
        .Send
    End With
     
    Application.ScreenUpdating = True
     
    Set Doc = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
        
    End Sub

    'Private Sub CommandButton1_Click()
    'ActiveDocument.HasRoutingSlip = True
    'With ActiveDocument.RoutingSlip
    '    .Subject = "Go Grant Application"
    '    .AddRecipient "sheronw@nhcconline.com"
    '    .Delivery = wdAllAtOnce
    'End With
    'ActiveDocument.Route
    'End Sub
    Friday, March 1, 2013 4:16 PM

Answers

  • You can use late binding. You already declare OL and EmailItem as objects.

    Replace olMailItem with 0 and olImportanceNormal with 1.

    Now select Tools | References and clear the check box for the Microsoft Outlook 14.0 Object Library.

    The code should work as long as the user has Outlook. It'll work best if the user has already started Outlook.


    Regards, Hans Vogelaar

    Friday, March 1, 2013 4:37 PM

All replies

  • You can use late binding. You already declare OL and EmailItem as objects.

    Replace olMailItem with 0 and olImportanceNormal with 1.

    Now select Tools | References and clear the check box for the Microsoft Outlook 14.0 Object Library.

    The code should work as long as the user has Outlook. It'll work best if the user has already started Outlook.


    Regards, Hans Vogelaar

    Friday, March 1, 2013 4:37 PM
  • sheronwallace, I was answered using your previous post.

    bdw, the same way...


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Sunday, March 3, 2013 11:17 AM
    Answerer