Log in

View Full Version : [SOLVED:] Error with Email code - Cant find project or library



AnthonAnthon
10-18-2017, 03:48 PM
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

heedaf
10-18-2017, 06:57 PM
I just tried it and it worked. Try checking Tools-->Reference and see if any of the MS Office librarys were unchecked.

gmayor
10-18-2017, 08:20 PM
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

macropod
10-18-2017, 10:00 PM
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.

AnthonAnthon
10-19-2017, 12:18 AM
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

macropod
10-19-2017, 12:25 AM
The one you set via Tools|References...