Results 1 to 8 of 8

How to email word document as an attachment with filename taken from text in document

Threaded View

  1. #1
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    How to email word document as an attachment with filename taken from text in document

    Hi,

    I have a word document to which few cells are linked from an excel sheet. what I am trying to do is send this word document in email as pdf attachment. The challenge is I want the file name to be the text that is being pulled from excel sheet. Following is the code I am using to email the document.

    Sub Saveandemail()
    
    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document
    Dim strFileName     As String
     
     Application.ScreenUpdating = False
        Set OL = CreateObject("Outlook.Application")
        Set EmailItem = OL.CreateItem(olMailItem)
        Set Doc = ActiveDocument
    
        strFileName = Replace(Doc.FullName, ".docm", ".pdf")
        Doc.ExportAsFixedFormat OutputFileName:=strFileName, _
            ExportFormat:=wdExportFormatPDF
     
        With EmailItem
            .Subject = ""
            .Body = ""
            .To = ""
            .Attachments.Add strFileName
            .Send
        End With
     
        Application.ScreenUpdating = True
    
        Set Doc = Nothing
        Set EmailItem = Nothing
        Set OL = Nothing
        
     End Sub
    Can you please help me how to get the filename to be the cell value that is linked to excel sheet.
    Last edited by laxminarayana; 03-05-2018 at 12:21 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. excel to paste to word then attach word document to an email
    By ahalliwell in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-30-2017, 12:44 PM
  2. [SOLVED] Creating email using Word document as email body – formatting lost
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-17-2016, 09:04 PM
  3. Replies: 0
    Last Post: 09-04-2014, 03:32 AM
  4. Replies: 2
    Last Post: 04-19-2013, 07:02 AM
  5. VBA - Create Word Document or Edit Document if exists
    By unstable81 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-11-2013, 08:27 AM
  6. Add text to Existing Word Document if it Doesn't exist create Word Document
    By unstable81 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2013, 12:15 AM
  7. [SOLVED] Changing a Word Document to a CSV Formated Document
    By Team1 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 02-06-2006, 07:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1