Share via

Prevent Command Button from Printing

Anonymous
2018-10-31T17:40:42+00:00

I am working in Word 2016. I’ve created a template, saved with the dotm extension.

The form has a command button for the user to e-mail the document. However, the Placement field must be completed before the user can e-mail it. Once the field is completed and the user clicks on the e-mail button again, they will need to save the template before it will be e-mailed. My coding below is working for all of this.

Private Sub CommandButton1_Click()

Dim OL As Object

Dim EmailItem As Object

Dim Doc As Document

Dim Msg, Style, Title, Response

With ActiveDocument.FormFields("Placement")

If Len(.Result) = 0 Then

Application.OnTime When:=Now + TimeValue("00:00:1"), Name:="GoBacktoPlacement"  

Msg = "You must complete the Date Placement Needed field in order to proceed."

Style = vbCritical

Title = "Date Placement Needed Entry"

Response = MsgBox(Msg, Style, Title)

Selection.GoTo wdGoToBookmark, Name:="Placement"

Else

Application.ScreenUpdating = False

Set OL = CreateObject("Outlook.Application")

Set EmailItem = OL.CreateItem(olMailItem)

Set Doc = ActiveDocument

Msg = "You must save this document before e-mailing it to the Placement Inbox."

Style = vbCritical

Title = "Save Document"

Response = MsgBox(Msg, Style, Title)

Dialogs(wdDialogFileSaveAs).Show

With EmailItem

.To = "email@address"

.Subject = "Placement Search Request"

.Body = ""

.Importance = olImportanceNormal

.Attachments.Add Doc.FullName

.Display

End With

Application.ScreenUpdating = True

Set Doc = Nothing

Set OL = Nothing

Set EmailItem = Nothing

Exit Sub

End If

End With

End Sub

When the Placement Team receives the e-mailed form and prints it out they do not want the E-mail command button to print. I’ve tried using the coding below, in multiple areas of the coding I provide above, but cannot get it to work.

With ActiveDocument

.Shapes(1).Visible = msoFalse

.PrintOut Background:=False

.Shapes(1).Visible = msoTrue

End With

I either get this message: The index into the specialized collection is out of bounds. – or the E-mail button still appears on the printed form.

Any help would be greatly appreciated.

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

9 answers

Sort by: Most helpful
  1. Anonymous
    2018-10-31T22:41:09+00:00

    >> What I'm looking for is when the receiver of the e-mailopens the document and they click on File, Print or if they have a Print button in the Quick Action Tool bar to click, that the document will print without the command button. <<

    You are asking for a lot here.

    The first question is whether the user will (or even can) allow your code to run. That is a big if.

    Much easier would be to add QAT buttons in your document/template for the email and print commands. Those require no code. If you send with instructions and maybe a screenshot of your QAT buttons that would work.

    Modifying the QAT:

    http://addbalance.com/word/QATmodification.htm


    This link is to a page on my website. It is safe. I am providing it because I think it contains information that will help you. However, as an Independent Advisor I am required to add the following when posting here with a link to any non-Microsoft site:


    Note: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.


    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2018-10-31T22:35:49+00:00

    It should work in a .dotm as well as in a .dot.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2018-10-31T17:56:16+00:00

    Hi Jamie,

    This is an old problem and was solved by the Word MVPs a while back.

    https://wordmvp.com/FAQs/TblsFldsFms/HidePrintB...


    This is a link to a Word MVP website. It contains accurate safe information that I think will help you. However, as an Independent Advisor I am required to give the following notice when providing non-Microsoft links:


    Note: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.


    I hope this information helps. Please let me know if you have any more questions or require further help.

    Regards

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2018-11-01T23:56:01+00:00

    Hi Charles, thanks for your suggestion on the QAT. I really don't want to go that route and hope that over 100 people will follow the instructions and add the buttons.

    I did get the E-mail command button not to print. The button was formatted as In line with text under the Layout tab in the Format Control. I changed the layout of the button to Square and the following coding works, but it does so automatically.

        With ActiveDocument

            .Shapes(1).Visible = msoFalse

            .PrintOut Background:=False

            .Shapes(1).Visible = msoTrue

        End With

    What I mean by, it does so automatically is, when the user clicks on the E-mail command button to e-mail the template to the Placement inbox, the template prints because the coding is associated with the command button.

    Can the above coding be used in a Sub FilePrint () so that when the receiver opens the e-mail and then the template, if they want to print the template, at that point they are doing so by File, Print not by the E-mail command button.

    If this is possible, what would the coding be?

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2018-10-31T20:57:35+00:00

    Hi Charles, thanks for your response. I did research this topic and found the coding that your link directed me to and I did incorporate that into my coding. However no matter where I placed it, the button would print out.

    I changed the template extension to dot and I again I've been placing the .Shapes coding in multiple places within my coding.  Now depending on where I place the .Shapes coding in the document either the button will print or document will print minus the button, but it prints when the receiver opens the e-mail automatically. What I'm looking for is when the receiver of the e-mail opens the document and they click on File, Print or if they have a Print button in the Quick Action Tool bar to click, that the document will print without the command button.

    I would love for this to work as well for the user sending the document; that if they need to print the document out after they complete it (before they send the e-mail) or after they have saved the document on their computer and bring it back up to print, that the command button does not print.

    Was this answer helpful?

    0 comments No comments