+ 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 2007
    Posts
    68

    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
    2,531

    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
    [MS MVP - Word]

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

    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
    2,531

    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 2007
    Posts
    68

    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
    2,531

    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 2007
    Posts
    68

    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
    2,531

    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)

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