Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2024, 02:43 PM
guyver4 guyver4 is offline vba Send Word document as email, not attachment Windows 11 vba Send Word document as email, not attachment Office 2016
Novice
vba Send Word document as email, not attachment
 
Join Date: May 2024
Posts: 2
guyver4 is on a distinguished road
Default vba Send Word document as email, not attachment

Hello everyone. I am wondering if I can get some help with this code I am using below.

While it currently sends the complete document text to Outlook as a Doc attachement,
I would like it to actually send the document contents to the body of the email.


Thanks.

Sub eMailActiveDocument()

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
Doc.Save
Doc.Content.Copy

With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub
Reply With Quote
  #2  
Old 05-17-2024, 04:44 AM
gmaxey gmaxey is offline vba Send Word document as email, not attachment Windows 10 vba Send Word document as email, not attachment Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,602
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim oEditor As Object
Dim Doc As Document

Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
Doc.Content.Copy

With EmailItem
  .Subject = "Insert Subject Here"
  .BodyFormat = olFormatRichText
        Set oEditor = .GetInspector.WordEditor
        oEditor.Content.Paste
  .To = "gmaxey@gregmaxey.com"
  .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
  .Display 'Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub

If you want to use "Send" instead "Display" you are probably going to have to insert a delay before killing the Outlook instance.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 05-17-2024, 05:14 AM
guyver4 guyver4 is offline vba Send Word document as email, not attachment Windows 11 vba Send Word document as email, not attachment Office 2016
Novice
vba Send Word document as email, not attachment
 
Join Date: May 2024
Posts: 2
guyver4 is on a distinguished road
Default

Hello Greg


Thank you for posting this, it worked perfectly!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a VBA Code to print then send as an email attachment bcfd_110 Word VBA 1 09-04-2022 01:53 PM
Help to get a word document to send specific content via email using submit button ActualJax Word VBA 2 07-06-2020 04:18 PM
Outlook macro to check a value of a cell in an attachment and send an email based on that value ketangarg86 Outlook 13 03-25-2015 07:11 AM
vba Send Word document as email, not attachment Command button - save in temp folder and send email with attachment bigbird69 Word VBA 13 11-18-2012 10:06 PM
vba Send Word document as email, not attachment sending word document as email attachment causes format loss gauntlett Word 1 04-27-2012 09:06 AM

Other Forums: Access Forums

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


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