Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 12-08-2022, 07:28 AM
gmayor's Avatar
gmayor gmayor is offline Attach file VBA with SharePoint file Windows 10 Attach file VBA with SharePoint file Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,143
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

Open the document in Word then run the following
Code:
Sub Rename_and_Send_As_Attachment()
'Graham Mayor - https://www.gmayor.com - Last updated - 08 Dec 2022
'Send the document as an attachment _
  in an Outlook Email message
'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.
Dim bStarted As Boolean
Dim OlApp As Object
Dim oItem As Object
Dim oDoc As Document
Dim strDocName As String
Dim strName As String
Dim strPath As String
    Set oDoc = ActiveDocument
    On Error GoTo Err_Handler:
    
    strPath = Environ("TEMP") & "\"
    'Replace %20 in the filename with a space
    strName = Replace(oDoc.Name, "%20", " ")
    strDocName = strPath & strName
    oDoc.SaveAs2 strDocName
    
    'Now close the document without saving as we have finished with it
    oDoc.Close 0
    'Get Outlook if it's running
    Set OlApp = OutlookApp()
    On Error GoTo 0
    'Create a new mailitem
    Set oItem = OlApp.CreateItem(0)

    With oItem
        .Subject = strName
        .attachments.Add strDocName
        .Display
    End With

lbl_Exit:
    Set oItem = Nothing
    Set OlApp = Nothing
    'Delete the temporary file
    Kill strDocName
    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
 

Tags
attachment, sharepoint, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Attach file VBA with SharePoint file Attach .xlsm file to Outlook email from whatever folder it's been saved in kiwimtnbkr Excel Programming 1 04-02-2022 11:32 PM
Cannot find file to attach in email megabyte Outlook 0 09-23-2020 05:35 AM
Button with VBA to attach a file in a protected document wolfgrrl Word VBA 6 09-20-2019 07:38 AM
Attach file VBA with SharePoint file Having Touble Finding Word File When Trying to Attach to Email freetibet213 Word 3 12-28-2011 05:26 AM
Attach a Excel file with Power point gmalpani Office 0 11-27-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:52 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