+ Reply to Thread
Results 1 to 8 of 8

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

  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.

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

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

    That really depends on 'how' the cell exists in the document. For example, if it's
    • contained in an embedded Excel worksheet, you'll have to open the embedded object and extract it from there.
    • just a text string retrieved via a LINK field, you could simply bookmark that field an retrieve the bookmark's contents.
    You need to provide more details.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

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

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

    I have used paste link option in word. So that should be a text string retrieved via a link. Can you please explain how to bookmark and what changes are required to the above code.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

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

    In that case, if you bookmark with LINK field with the name 'Filename', for example, you could replace:
    strFileName = Replace(Doc.FullName, ".docm", ".pdf")
    Doc.ExportAsFixedFormat OutputFileName:=strFileName, _
    ExportFormat:=wdExportFormatPDF
    with:
    Please Login or Register  to view this content.
    Last edited by macropod; 03-05-2018 at 04:24 PM.

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

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

    Thank You! very much. That worked after a small change to the code, as document was closing when macro was run.

    Please Login or Register  to view this content.
    I'm sorry but still there is a problem. Every time the macro is run, copy of the pdf file is getting saved in the folder. The pdf file is to be only an attachment but not in folder
    Last edited by laxminarayana; 03-06-2018 at 02:11 PM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

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

    You can attach a file that hasn't been saved. You could add a line to the code to delete the pdf after the email has been sent. For example:
    Please Login or Register  to view this content.

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

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

    Once again Thank You!
    How can I learn and master vba like you?

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

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

    The only way is to study VBA coding - for which you can learn from the coding of others - and use it. The last part is particularly important: use it or lose it!

+ Reply to Thread

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] [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