none
Make a macro button to e-mail that works when the document is protected RRS feed

  • Question

  • Hi

    I have a code and a macro button that sends the document to outlook. But I can't get it to work when I protect the document. I wan't the users to fill the forms and push the macro buttons in the word document. And it would also be good if when I push the macro button to send the document to outlook then the document is in PDF format not Word.

    Is there anyone who knows a solution to just simply have a button in the protected word document that simply let the users to push it so outlook opens and you see the document attached in PDF format?

    Attribute VB_Name = "sendeMail"
    Sub sendeMail()
    Dim olkApp As Object
    Dim strSubject As String
    Dim strTo As String
    Dim strBody As String
    Dim strAtt As String
    
        strSubject = "Whatever!"
        strBody = "Please see attached File"
        strTo = ActiveDocument.FormFields("epost").Result
        If ActiveDocument.FullName = "" Then
            MsgBox "activedocument not saved, exiting"
            Exit Sub
        Else
            If ActiveDocument.Saved = False Then
                If MsgBox("Activedocument NOT saved, Proceed?", vbYesNo, "Error") <> vbYes Then Exit Sub
            End If
        End If
        strAtt = ActiveDocument.FullName
        
        Set olkApp = CreateObject("outlook.application")
        With olkApp.CreateItem(0)
            .To = strTo
            .Subject = strSubject
            .Body = strBody
            .Attachments.Add strAtt
            '.send
            .Display
        End With
        Set olkApp = Nothing
    End Sub
    

    Regards

    Friday, January 8, 2016 1:27 PM

Answers

  • Use the .ExportAsFixedFormat command to export the document to a pdf file and attach the pdf file.

    With ActiveDocument
        .ExportAsFixedFormat Left(.Fullname, InstrRev(.Fullname, ".") & "pdf", _ wdExportFormatPDF, False, wdExportOptimizeForPrint
        strAttach = Left(.Fullname, InstrRev(.Fullname, ".") & "pdf"
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    Saturday, January 9, 2016 5:09 AM

All replies

  • Hello,

    As this is for Word to Outlook I am moving your question to the Word for Developer's forum for better assistance with this question.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    Friday, January 8, 2016 1:42 PM
  • Hi, it looks like you're working with VBA in Word.  This forum is for Visual Basic .NET, which is a quite different animal.  You'll likely have some more luck posting to these forums:

    MSDN VBA Forum

    MSDN Word for Developers Forum

    Hope you find what you're looking for!

    Friday, January 8, 2016 1:46 PM
  • Please provide details about HOW it doesn't work. Do you get an error? On which line of code?


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Friday, January 8, 2016 4:53 PM
    Moderator
  • Hello Cindy

    I do not get any error. Everything works fine until I protect the document so that people can't edit the document only filing out the form fields and dropdowns. When I try to click the macro button in the protected document then the Word document only scroll down one page. But when I unlock the Word document then the macro button works fine. 

    I simply look for a way to make a macro button that runs the "sendeMail" in a protected mode and also so that the document could be in a .pdf version when the macro attach it to the Outlook e-mail.
    Friday, January 8, 2016 6:36 PM
  • I think you need to be more precise about to what you're referring with the term "macro button". A MacroButton field is not locked out when a document is protected as a form - the macro runs. So you must be using something else...

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Friday, January 8, 2016 7:18 PM
    Moderator
  • Thank you Cindy for quick respond. I actually found out that I was just using the macro setup wrong. But is there a way to attach the Word document as a .pdf file to Outlook automatically? By this I mean when I push the button that runs the process "the code I wrote in the first post above" that will attach the word document into Outlook e-mail in a pdf file not a doc file. I don't want to send it as a a word document only pdf file.
    Friday, January 8, 2016 8:15 PM
  • Use the .ExportAsFixedFormat command to export the document to a pdf file and attach the pdf file.

    With ActiveDocument
        .ExportAsFixedFormat Left(.Fullname, InstrRev(.Fullname, ".") & "pdf", _ wdExportFormatPDF, False, wdExportOptimizeForPrint
        strAttach = Left(.Fullname, InstrRev(.Fullname, ".") & "pdf"
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    Saturday, January 9, 2016 5:09 AM
  • Thank you Doug. I will try it later today when I'm home at my computer and let you know how it went. Is it just to put at the bottom of the code before the "End Sub"?
    Saturday, January 9, 2016 11:57 AM
  • Hi thoart,

    Have your issue been resolved? If you have, I suggest you mark the helpful reply as answer to close this thread.

    >> Is it just to put at the bottom of the code before the "End Sub"?
    With Doug’s code, you would get a pdf file path, you could add attachment with this file path.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, January 11, 2016 2:57 AM
  • Thank you for the advice Edward :-)
    Monday, January 11, 2016 8:19 PM
  • Hello, Did you actually find a solution for the initial problem - the button stops working after you protect the document?

    I get exactly the same with an ActiveX control button on a protected form.

    When the document is unprotected it fires correctly on the onClick (I do exactly the same as you - launch outlook message with PDF attachment)

    When I protect the document for form entry only the button only fires the click function when I drag the mouse over the button.

    How did you solve your issue?

    Wednesday, March 2, 2016 9:23 AM