Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2019, 07:29 AM
Kieranf Kieranf is offline Problem with submitting a word form via email. Windows 7 64bit Problem with submitting a word form via email. Office 2019
Novice
Problem with submitting a word form via email.
 
Join Date: Feb 2019
Posts: 1
Kieranf is on a distinguished road
Default Problem with submitting a word form via email.

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
Reply With Quote
  #2  
Old 02-13-2019, 03:27 PM
Guessed's Avatar
Guessed Guessed is offline Problem with submitting a word form via email. Windows 10 Problem with submitting a word form via email. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Has the activedocument been saved before running the code?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-13-2019, 09:51 PM
gmayor's Avatar
gmayor gmayor is offline Problem with submitting a word form via email. Windows 10 Problem with submitting a word form via email. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you are using late binding to Outlook you need to change two lines
Code:
Set EmailItem = OL.CreateItem(0)
and
Code:
.Importance = 1    'Or olImportanceHigh (2) Or olImportanceLow (0)
Word doesn't recognize Outlook specific commands and you must use the numeric equivalents.
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
Reply With Quote
Reply

Thread Tools
Display Modes


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
Problem with submitting a word form via email. 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
Problem with submitting a word form via email. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft