Consulting

Results 1 to 6 of 6

Thread: Error with Email code - Cant find project or library

  1. #1

    Question Error with Email code - Cant find project or library

    Good afternoon!
    I am using this code with my document attached to a button.
    Private Sub PolkButton_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
    Doc.Save
    With EmailItem
    .Subject = "Polk County Placement"
    .Body = "" & vbCrLf & _
    "" & vbCrLf & _
    ""
    .To = "email"
    .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
    .Attachments.Add Doc.FullName
    .Display
    End With
    Application.ScreenUpdating = True
    Set Doc = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
    End Sub
    Yesterday it was working flawlessly. today I'm getting this error " Cant find project or library" on this piece of code
    olMailItem
    Any idea how I can fix this? I have googled and searched around and found others with the same issue but no fixes that I was able to find

  2. #2
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    I just tried it and it worked. Try checking Tools-->Reference and see if any of the MS Office librarys were unchecked.

  3. #3
    If you are using late binding to Outlook you need the numeric equivalents of Outlook specific commands so

    Set EmailItem = OL.CreateItem(0)
    
    .Importance = 1
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by gmayor View Post
    If you are using late binding to Outlook
    I suspect that's happened because someone deleted the Outlook Reference, so now the code has a mix of late binding:
    Dim OL As Object
    Dim EmailItem As Object
    constructs and early binding:
    OL.CreateItem(olMailItem)
    .Importance = olImportanceNormal
    constructs and it fails on the latter.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Quote Originally Posted by macropod View Post
    I suspect that's happened because someone deleted the Outlook Reference, so now the code has a mix of late binding:
    Dim OL As Object
    Dim EmailItem As Object
    constructs and early binding:
    OL.CreateItem(olMailItem)
    .Importance = olImportanceNormal
    constructs and it fails on the latter.
    What reference am I looking for?
    This document is meant to be put onto several people's desktops and used individually, will they all have to search out this reference and enable it, and will they have to do this each time?
    It worked fine for me just a day ago, and then didnt today, and once I give it to everyone I wont be able to fix it if that happens again

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The one you set via Tools|References...
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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