olMailItem Which Reference Do I need?

J

JBark

I keep trying to use some vba code and keep running across compile errors.
How can I find out which reference needs to be "checked" on for the code to
run?

Like this is my newest one that won't run "olMailItem". What reference does
this belong to that I must turn on?

Thanks.
 
D

Doug Robbins - Word MVP

I could be more positive if you showed all of the code, but it is almost
certainly a reference to the Microsoft Outlook # Object Library that is
missing.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
S

Steve Yandl

It's from Microsoft Outlook. If you have Office 2007, it would be
Microsoft Outlook 12 Object Library

It's the contsant for email message type items.

Steve Yandl
 
J

JBark

This is the code. I followed instructions from the MVP site. And Yes, I
already checked; the "Microsoft Outlook 11.0 Object Library is checked on.
I'm using Word 2003 on Windows XP 2002 SP2. The original document will be
protected when completed then saved as a template .dot file for other users
to fill out like a form and submit via email as an attachment.

Private Sub SendDocumentAsAttachment()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed)"
.Subject = "PO# " & ActiveDocument.FormFields("POrequired").Result _
& " " & ActiveDocument.FormFields("CLIENTrequired").Result _
& " " & ActiveDocument.FormFields("PRODUCTrequired").Result
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Display
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

End Sub
 
D

Doug Robbins - Word MVP

Check the reference again. It would not be the first time that I have
suggested to someone that they do that and they have reported back that it
was not checked.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

JBark

Thanks Doug. I found the problem. The Outlook reference was checked on, but
so was Normal-MISSING. I turned that one off and everything is fine now. I'm
not the only one who uses the computer. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top