none
HELP! with a word document code RRS feed

  • Question

  • I am adding a command button to a word document.  This document will be used for employees to submit an absence request. When they click on the command button it will email the document to several people.  The code  seems to work for me when I click on the "submit" command button, but when I have another person try it they receive this error:  Compile Error:  Can't find project or Library.  Here is the code I'm using.....the underlined line of code seems to be the cause.  Any help would be appreciated!  

    Private Sub CommandButton1_Click()
    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document
     
    Application.ScreenUpdating = False
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set Doc = ActiveDocument

     
    With EmailItem
        .Subject = "Absence Request"
        .Body = "Thank you" & vbCrLf & _
        "-" & vbCrLf & _
        "_"
        .To = "Email.com;email.com"
        .CC = "email.org"
        .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

    Application.ActiveDocument.Close

      

    End Sub

    Thursday, August 17, 2017 1:42 PM

All replies

  • Do the other users have Outlook installed, or an older version than yours? You are using late-binding to create the Outlook instance but I wonder if you have added a Reference to the Outlook library in your Word document. If so, I would try removing it and hard-coding any enumerated constants (such as olMailItem, which is 0).


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Thursday, August 17, 2017 4:15 PM
  • Hi beechers,

    Can you please tell us what is your project? vb.net or other?  This forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools .

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 18, 2017 8:54 AM
  • Hello, 

    This forum is for VB in Visual Studio. Your VB is probably VBA (although there is a light chance it is a vintage version of VB) VBA is done in the  VBA forum.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=isvvba


    Success
    Cor

    Friday, August 18, 2017 10:32 AM
  • Hello,

    As Cor stated, this is not the correct forum so I'm moving your question to the proper forum.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, August 18, 2017 10:51 AM
  • Thank you!
    Friday, August 18, 2017 6:24 PM
  • Hi beechers,

    I try to test the code on my side.

    I get the error on same line.

    I get error below.

    I add the reference to Outlook Object Library. it solves this error.

    other thing you had mentioned that you are adding this button to the document. so do you adding the button to a new document or sharing the same document to all Employees?

    I suggest you to create one document with the user form. and then share it to all employees.

    so that employee just need to fill the information in UserForm and not need to make any changes in the code.

    also it is a user friendly approach to solve this issue.

    you can lock the VBA code and provide document to them for apply leave.

    also need to make sure that when you run above code , the document need to be saved otherwise user will receive an error.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 22, 2017 7:08 AM
    Moderator