Thread: [Solved] Telephone Enquiry Form
View Single Post
 
Old 05-27-2016, 09:01 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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 ofgmayor has much to be proud of
Default

This is in fact very easy to achieve. Setup a template featuring a form comprising a two column table with the descriptions in the left column and legacy form fields in the right column. Add an ActiveX button below the table call the e-mail function

Put the button code in the ThisDocument module of the template e.g.
Code:
Option Explicit
Private Sub CommandButton1_Click()
Send_As_HTML_EMail
End Sub
Put this code in a new ordinary module of the template. Change the e-mail address and subject as appropriate
Code:
Sub Send_As_HTML_EMail()
'Graham Mayor - www.gmayor.com
Dim bStarted As Boolean
Dim olApp As Object
Dim oItem As Object
Dim orng As Range
Dim objdoc As Object
Dim objSel As Selection
    On Error Resume Next
    Set orng = ActiveDocument.Range
    orng.Copy
    'Get Outlook if it's running
    Set olApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        'Outlook wasn't running, start it from code
        Set olApp = CreateObject("Outlook.Application")
        bStarted = True
    End If
    'Create a new mailitem
    Set oItem = olApp.CreateItem(0)
    With oItem
        .BodyFormat = 2
        .Display
        Set objdoc = .GetInspector.WordEditor
        Set objSel = objdoc.Windows(1).Selection
        objSel.Paste
        .to = "test@mail.com"
        .Subject = "The subject"
        .Send
    End With
    If bStarted Then
        'If we started Outlook from code, then close it
        olApp.Quit
    End If
    'Clean up
    Set oItem = Nothing
    Set olApp = Nothing
lbl_Exit:
    Exit Sub
End Sub
Protect the document for forms and save as a macro enabled template.

See http://www.gmayor.com/extract_email_data_addin.htm for a means of processing the data from the messages.
__________________
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