Share via

do not print command buttons

Anonymous
2013-04-18T17:23:20+00:00

I have a form with a few command buttons on them to help you add rows of data or delete rows of data when the document is protected to allow the final form to be more visual. How do I make it so that these command buttons do not print. I read an article about cutting and pasting them into a text box but that didnt seem to work

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

4 answers

Sort by: Most helpful
  1. Anonymous
    2013-04-23T14:41:55+00:00

    So this is the macro I put into the new module under my specific project, and and when I push print it brings up the error at the bottom...

    Sub FilePrint()

        With ActiveDocument

            .Shapes(Textbox19).Visible = msoFalse

            .Shapes(Textbox26).Visible = msoFalse

    '       continue this list until all the text box indexes are included

            .PrintOut Background:=False

            .Shapes(Textbox19).Visible = msoTrue

            .Shapes(Textbox26).Visible = msoTrue

            '       continue this list until all the text box indexes are included

        End With

    End Sub

    Error Message: "The index into the specified collection is out of bounds"

    It highlights the first line of code ".Shapes(Textbox19).Visible = msoFalse"

    As a side note the way that I discovered the name of the textbox (which maybe is the problem....) was I did record macro and then from the home tab i pushed the select button (looks like a mouse pointer) and did select object.  Then I selected the textbox I pasted the button into. I finished recording and just looked at what textbox was selected. If this method is wrong and gives me  a different name then let me know and I can go back and figure out the names the way you said, but I think I have the correct names.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2013-04-19T03:22:16+00:00

    OK, that's a different situation than the article assumes. You'll need to make some changes...

    First, if the button (or you said several buttons) aren't for causing the document to print, then you don't want to use the Click procedure of the button (e.g., Sub CommandButton1_Click). Instead, you need to create a macro (in a regular module in the document, not in the ThisDocument module) with the special name FilePrint. A macro with that name will run instead of the built-in Print command. Inside that macro, you can make all of the command buttons invisible, call the .PrintOut method to do the printing, and then make all of the buttons visible again.

    Second, the macro in the article assumes that there are no other text boxes or drawn shapes in the document (or if there are, then the text box containing the command button is the first shape). My guess is that this isn't true in your document, so the code made some other shape invisible --  whatever is .Shapes(1).

    So...

    In the document, put each command button into its own text box. You'll have to find out the index number of the text box (shape) for each one. There's no easy way to do this, but here's a way: In the document, click the ¶ button so you can see the paragraph marks. In the VBA editor, press Ctrl+G to open the Immediate window. Paste in this line and press Enter:

    ActiveDocument.Shapes(1).TextFrame.TextRange.Font.Color=wdColorRed

    Look at the document to see whether the paragraph mark in any of the text boxes has turned red. If so, you know that's .Shapes(1). Change it back to black by changing wdColorRed to wdColorAutomatic and pressing Enter. Then change the 1 to 2, change to wdColor Red again, and repeat. Keep going until you've found the index numbers of all the text boxes.

    In the VBA editor, delete the Sub CommandButton1_Click procedure. Click Insert and click Module. Then add code like this:

    Sub FilePrint()

        With ActiveDocument

            .Shapes(1).Visible = msoFalse

            .Shapes(2).Visible = msoFalse

    '       continue this list until all the text box indexes are included

            .PrintOut Background:=False

            .Shapes(1).Visible = msoTrue

            .Shapes(2).Visible = msoTrue

    '       continue this list until all the text box indexes are included

        End With

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-04-18T19:44:46+00:00

    Yes this was the article.

    there was two problems with the button. First I am not creating a print button, the button serves another purpose, but I do not want it to be visible when the document is printed. The macro listed in the article calls to print the page, but when it printed the buttons were still visible anyways.

    Was this answer helpful?

    0 comments No comments
  4. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2013-04-18T17:49:54+00:00

    Was this the article you saw? http://www.word.mvps.org/FAQs/TblsFldsFms/HidePrintButton.htm

    If so, exactly what happened when you tried it? If you got any error message, what was the exact wording of the message?

    Was this answer helpful?

    0 comments No comments