![]() |
|
#1
|
|||
|
|||
|
I have created the following code (via a lot of searching) but the attached form is blank. Can anyone see what is wrong?
Code:
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 = "Hello"
.Body = "Insert message here or just send"
.To = "acas-media@media.co.uk"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
.Save
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
|
|
#2
|
||||
|
||||
|
Has the activedocument been saved before running the code?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#3
|
||||
|
||||
|
If you are using late binding to Outlook you need to change two lines
Code:
Set EmailItem = OL.CreateItem(0) Code:
.Importance = 1 'Or olImportanceHigh (2) Or olImportanceLow (0) If you want to keep the signature or edit the message body directly, you will need to use the following - note the comment at the top Code:
Private Sub CommandButton1_Click()
'Use the code from http://www.rondebruin.nl/win/s1/outlook/openclose.htm
'To open Outlook correctly or this won't work
Dim OL As Object
Dim EmailItem As Object
Dim olApp As Object
Dim olInsp As Object
Dim Doc As Document
Dim wdDoc As Object
Dim oRng As Object
Application.ScreenUpdating = False
Set OL = OutlookApp()
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
With EmailItem
.Subject = "Hello"
.to = "acas-media@media.co.uk"
.Importance = 1 'Or olImportanceHigh (2) Or olImportanceLow (0)
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.Collapse 1
oRng.Text = "Insert message here or just send"
.Attachments.Add Doc.FullName
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Set olInsp = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pulling info from an email into a form on Word | jlamx | Word | 1 | 07-07-2017 08:24 PM |
Adding email button to Word form
|
leilers | Word | 5 | 01-09-2012 03:21 PM |
| Submitting HTML form data in Outlook 2010 | ramen | Outlook | 0 | 12-15-2011 02:29 PM |
Word Form Problem
|
firewatch | Word | 1 | 11-08-2011 02:23 AM |
| MS Word form - email button | floydwood | Word VBA | 0 | 05-10-2009 04:11 PM |