Re: Word 2010 - VB CommandButton - Printing, but don't want to print button

Subject: Re: Word 2010 - VB CommandButton - Printing, but don't want to print button
From: Tony Chung <tonyc -at- tonychung -dot- ca>
To: Emoto <emoto1 -at- gmail -dot- com>, TECHWR-L <techwr-l -at- lists -dot- techwr-l -dot- com>
Date: Tue, 21 Apr 2015 10:29:27 -0700

Here's kind of what I mean (This is quick and dirty, and not built for
code-efficiency, just understanding):

*** IMPORTANT: This only works for Office 2010 and later. Office 2007
requires a kludgey-but-fun method that involves XML and text editors. ***

1. Open your macro-enabled Word document (docm)

2. Press ALT-F11 to open the Developer window.

3. If a Module with your code doesn't appear:
a) Check the left menu. Below Project (document name) should be a
Modules folder, and within the folder, a module that could be named "Module
1". Click the Module name.
b) If there isn't a Modules folder, right-click Project (document) and
choose Insert > Module
A Modules folder is created, and a Module 1 module window opens.

4. Paste the following code:
Sub PrintP6()
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="6"
End Sub

Sub PrintP4_5()
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="4-5"
End Sub

Sub PrintP2_3()
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="2-3"
End Sub

*** NOTE: The reason your other macros might not have worked is because
they were set as Private Sub routines, but no Public calling Sub routine.
***

5. Close the Developer window and save the document.

*** TIP: Remember the ALT-F11 keyboard shortcut. This is how you can open
the macros window to copy the code to set up different page ranges.

6. In your macro-enabled document, right-click the ribbon and choose
Customize the Ribbon.

7. Use the drop down arrow to select Choose commands from: Macros. The
three macros should appear as:
* Project.Module1.PrintP2_3
* Project.Module1.PrintP4_5
* Project.Module1.PrintP6

8. From the bottom the Customize the Ribbon: column, click New Tab. Leave
the default names as they are. You can always use Rename later.

9. Click the New Group to make it active.

10. Select each macro from the left and click Add >> to copy it to the
right.

11. Click OK.

There should be a new tab with three really ugly buttons. Test them so that
the print features work.

>From this point:
* Add new macros to set print ranges, then add the new macros to the ribbon.
* Customize the Ribbon again to change the name of the tab, the group, the
macros, and the icon.

Hope this helps.

If you really really really want the code to hide the buttons:

1. First define a control group to hold the buttons in. In this example,
assume Shapes(1) is a group.

2. Use code that looks like something this:

Private Sub CommandButton1_Click()
Call PrintControl("6")
End Sub

Private Sub CommandButton11_Click()
Call PrintControl("4-5")
End Sub

Private Sub CommandButton21_Click()
Call PrintControl("2-3")
End Sub

Private Function PrintControl( PageNums as String )
With ActiveDocument
.Shapes(1).Visible = msoFalse
.PrintOut Background:=False
.PrintOut Range:=wdPrintRangeOfPages, Pages:=PageNums
.Shapes(1).Visible = msoTrue
End With
End Function

All that's missing is error handling.

Cheers,
-Tony


On Tue, Apr 21, 2015 at 9:50 AM, Tony Chung <tonyc -at- tonychung -dot- ca> wrote:

> Why are you creating the buttons in the document? Why don't you just add a
> button to the ribbon? The document can display the button when the document
> opens, then remove the button when the document closes.
>
> That's the proper design pattern.
>
> -Tony
>
> On Tue, Apr 21, 2015 at 6:39 AM, Emoto <emoto1 -at- gmail -dot- com> wrote:
>
>> Greetings fellow tech writers!
>>
>> I am not a VB guy, but at a client's request and with great fear &
>> loathing, have set up a Word 2010 doc (.docm) so that it will have buttons
>> in it that print designated pages when clicked. I have that part working
>> ok.
>>
>> What I am struggling with is how to incorporate the code to print the
>> pages, but not show the button on the printed pages.
>>
>> My code looks like this:
>>
>> Private Sub CommandButton1_Click()
>> ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="6"
>> End Sub
>> _____________________________________________________________________
>>
>> Private Sub CommandButton2_Click()
>>
>> End Sub
>> _____________________________________________________________________
>>
>> Private Sub CommandButton11_Click()
>> ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="4-5"
>> End Sub
>> _____________________________________________________________________
>>
>> Private Sub CommandButton21_Click()
>> ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="2-3"
>> End Sub
>>
>> The code I find that seems to be what I want is:
>>
>> Private Sub CommandButton1_Click()
>>
>> With ActiveDocument
>> .Shapes(1).Visible = msoFalse
>> .PrintOut Background:=False
>> .Shapes(1).Visible = msoTrue
>> End With
>>
>> End Sub
>>
>>
>> I haven't been able to figure out how/where to incorporate any of this
>> without getting errors, or I get no error, but the button remains visible.
>>
>> Can anyone please show me what to put where, so that I will still print my
>> pages, but the button won't show? I try to avoid VB....
>>
>> Thanks!
>>
>> Bob
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> Adobe TCS 5: Get the Best of both worlds: modern publishing and best in
>> class XML \ DITA authoring | http://adobe.ly/scpwfT
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> You are currently subscribed to TECHWR-L as tonyc -at- tonychung -dot- ca -dot-
>>
>> To unsubscribe send a blank email to
>> techwr-l-leave -at- lists -dot- techwr-l -dot- com
>>
>>
>> Send administrative questions to admin -at- techwr-l -dot- com -dot- Visit
>> http://www.techwhirl.com/email-discussion-groups/ for more resources and
>> info.
>>
>> Looking for articles on Technical Communications? Head over to our
>> online magazine at http://techwhirl.com
>>
>> Looking for the archived Techwr-l email discussions? Search our public
>> email archives @ http://techwr-l.com/archives
>>
>
>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adobe TCS 5: Get the Best of both worlds: modern publishing and best in class XML \ DITA authoring | http://adobe.ly/scpwfT

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You are currently subscribed to TECHWR-L as archive -at- web -dot- techwr-l -dot- com -dot-

To unsubscribe send a blank email to
techwr-l-leave -at- lists -dot- techwr-l -dot- com


Send administrative questions to admin -at- techwr-l -dot- com -dot- Visit
http://www.techwhirl.com/email-discussion-groups/ for more resources and info.

Looking for articles on Technical Communications? Head over to our online magazine at http://techwhirl.com

Looking for the archived Techwr-l email discussions? Search our public email archives @ http://techwr-l.com/archives


Follow-Ups:

References:
Word 2010 - VB CommandButton - Printing, but don't want to print button: From: Emoto
Re: Word 2010 - VB CommandButton - Printing, but don't want to print button: From: Tony Chung

Previous by Author: Re: Word 2010 - VB CommandButton - Printing, but don't want to print button
Next by Author: Re: finding an instructional design / e-learning contractor
Previous by Thread: Re: Word 2010 - VB CommandButton - Printing, but don't want to print button
Next by Thread: Re: Word 2010 - VB CommandButton - Printing, but don't want to print button


What this post helpful? Share it with friends and colleagues:


Sponsored Ads