Share via

I would like to export my Word Doc as pdf file and send it as an attachment in Outlook email?

Anonymous
2024-02-25T17:12:32+00:00

Can someone please help me out with the code for a button called Send Email.

Thanks

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Charles Kenyon 166.8K Reputation points Volunteer Moderator
    2024-02-25T18:24:28+00:00

    You can easily add the following to your QAT.

    Image.

    The E-Mail as PDF Attachment creates the pdf and attaches it to an email ready to be addressed and sent. It uses the default email program.

    Image.

    You want to choose commands from under the File Tab. The command/menu is Send.

    If you want you can save the QAT modification in a document or template rather than in the default on your computer. This will mean it would be available for anyone using the template even if not on your computer. See step (6) in the screenshot.

    Modifying the Quick Access Toolbar (QAT) in Microsoft Word

    Note: The default text for that button is Send but you could change it to Send E-Mail if you want.

    I assume that by button, you meant an ActiveX button which requires macros. This does not require any macro and would not have to be saved in a .docm/.dotm file. It likely will also work on a Mac while ActiveX would not.

    2 people found this answer helpful.
    0 comments No comments
  2. Charles Kenyon 166.8K Reputation points Volunteer Moderator
    2024-02-25T18:06:29+00:00

    First, have you done:

    File > Share > Email > PDF Attachment?

    You want something shorter?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2024-02-25T22:27:08+00:00

    i used the following and still getting an error when i try to complete.

    Compile error:

    Expected End Sub

    I don't know how to fix the bug can you help me.

    Private Sub CommandButton1_Click()

    Sub SendAsPDF()

    Dim strFileName As String 
    
    Dim objOutlook As Object 
    
    Dim objMailItem As Object 
    

    ' Replace .docx with .pdf

    strFileName = Replace(ActiveDocument.FullName, ".docx", ".pdf") 
    

    ' Export the document as PDF

    ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, \_ 
    
        ExportFormat:=wdExportFormatPDF 
    

    ' Create a new mail item

    Set objOutlook = CreateObject("Outlook.Application") 
    
    Set objMailItem = objOutlook.CreateItem(0) ' 0 = olMailItem 
    

    With objMailItem

        .Subject = "New Threat Assessment" 
    
        .Body = "Attached is a new threat assessment" 
    
        .To = "******@gmail.com" 
    
        .Attachments.Add strFileName 
    
        .Display  ' or . Send 
    
    End With 
    

    ' Clean up

    Set objMailItem = Nothing 
    
    Set objOutlook = Nothing 
    

    End Sub

    0 comments No comments
  4. Anonymous
    2024-02-25T18:04:21+00:00

    Hello Victor,

    I'm Shalom and I'd happily help you with your question. In this forum, we are Microsoft consumers just like yourself.

    Sure, I can help with that. Here’s a VBA code snippet that you can use to create a button called “Send Email” in Word. This code will export your Word document as a PDF and send it as an attachment in an Outlook email.

    Sub SendAsPDF() Dim strFileName As String Dim objOutlook As Object Dim objMailItem As Object

    ' Replace .docx with .pdf strFileName = Replace(ActiveDocument.FullName, ".docx", ".pdf")

    ' Export the document as PDF ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, _ ExportFormat:=wdExportFormatPDF

    ' Create a new mail item Set objOutlook = CreateObject("Outlook.Application") Set objMailItem = objOutlook.CreateItem(0) ' 0 = olMailItem

    With objMailItem . Subject = "Your Subject" . Body = "Your Message" . To = "Recipient's Email Address" . Attachments.Add strFileName . Display ' or . Send End With

    ' Clean up Set objMailItem = Nothing Set objOutlook = Nothing End Sub

    You can replace "Your Subject", "Your Message", and "Recipient's Email Address" with your actual subject, message, and recipient’s email address.

    Please note that this code requires Microsoft Outlook to be installed on your computer.

    Best Regards, Shalom

    0 comments No comments
  5. Anonymous
    2024-02-25T17:33:19+00:00

    Open your Word File, go to File Save As and select PDF as your file type.

    0 comments No comments