View Single Post
 
Old 01-04-2022, 10:48 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

The document would have to be saved as macro enabled and contain all the code. This creates its own problems as you cannot force a user to enable or run the macros. However ...

Assuming an ActiveX check box, associate the following code with the checkbox -
Code:
Option Explicit

Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
        ActiveDocument.Save
        Return_As_Mail_Attachment
    End If
End Sub

The following in a new module will send the current document as an e-mail attachment. NOTE THE COMMENTS!:


Code:
Option Explicit

Sub Return_As_Mail_Attachment()
'Graham Mayor - https://www.gmayor.com - Last updated - 05 Jan 2022
'Send the document as an attachment _
  in an Outlook Email message

'IMPORTANT *******
'Requires the code from - http://www.rondebruin.nl/win/s1/outlook/openclose.htm
'to either retrieve an open instance of Outlook or open Outlook if it is closed.
'*****************

Const sAddress As String = "someone@somewhere.com"    '"your email address"
Const strMessage As String = "This is the message text" & vbCr & _
      "Completed document is attached"

Dim OlApp As Object
Dim olInsp As Object
Dim oItem As Object
Dim oDoc As Document, eMailDoc As Document
Dim oRng As Range
Dim sPath As String
Dim sName As String
    Set oDoc = ActiveDocument
    On Error GoTo err_Handler:
    sPath = oDoc.FullName
    sName = oDoc.Name
    oDoc.Close 0
    'Get Outlook if it's running
    Set OlApp = OutlookApp()
    'Create a new mailitem
    Set oItem = OlApp.CreateItem(0)

    With oItem
        .to = sAddress
        .Subject = sName & " completed"
        .attachments.Add sPath
        Set olInsp = .GetInspector
        Set eMailDoc = olInsp.WordEditor
        Set oRng = eMailDoc.Range
        oRng.Collapse 1
        .Display
        oRng.Text = strMessage & vbCr
        .send
    End With

lbl_Exit:
    Set oItem = Nothing
    Set OlApp = Nothing
    Set olInsp = Nothing
    Set oRng = Nothing
    Set oRng = Nothing
    Exit Sub
err_Handler:
    Err.Clear
    GoTo lbl_Exit
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