?
Solved

Adding a "print" button to a Word document

Posted on 2003-02-28
14
Medium Priority
?
574 Views
Last Modified: 2008-03-17
I'm creating a form in Word and would like to add a "print" button that the users can just click to print.

I've added a button via the control toolbox, but I can't figure out how to assign my printing macro to it.

Also, I don't want the button itself to print.  I know how to supress an object's printing in Excel but I can't figure it out in Word.
0
Comment
Question by:thartin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8041965
This should do it:

CommandButton1.Visible = False
UserForm1.PrintForm
CommandButton1.Visible = True

i.e. hide the button then print.

Is that what you mean?

Steve
0
 
LVL 3

Expert Comment

by:MandyC
ID: 8042015
To assign the macro to the button copy your macro code then right click the button. Pick view code from this list and paste in your code. Add dragon-it's code as required to hode/reshow the button.

Hope this works

Mandy
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8042024
Reading it again I had assumed you had a user form but now it sounds more like a document layed out as a form with a print button on it.  Buttons on the page get lumped in with drawing objects so this would work:

Options.PrintDrawingObjects = False / True

As long as you don't have any other drawing objects that need printing...

Anyone else got better ideas?

Steve
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:thartin
ID: 8042469
Mandy, nice work on the macro idea, it works perfectly :)

Dragon-it, yes I am just using a regular document that will probably get saved as a .DOT.  Unfortunately I do have other drawing objects (some text boxes and graphics) that your code also prevented from printing.  Any other ideas?
0
 
LVL 1

Expert Comment

by:MacroWizard
ID: 8042861
If you are going to save the form as a template (DOT file), why don't you add a toolbar and assign the macro to it? Then there will be no question of printing the button.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8043007
True, was going to suggest that.  Or a cutom menu bar... useful for putting "About" documents, and any other command useful for this document.

e.g.

http://www.mvps.org/word/FAQs/MacrosVBA/AddMenu.htm

Steve
0
 

Author Comment

by:thartin
ID: 8043241
I've never used custom toolbars-- would it automatically work on any computer that loaded this file (this file will reside on a public drive for many people to use)?

I like the flexibility in being able to place a button anywhere on the document so that I can put it near where most people's cursors are.  I might try to re-design the form a bit so that I can use dragon-it's method of supressing the printing.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8043466
Yes they can load with the document and be removed when it is closed -- as long as you add them from the Dcoument_Open (Or Document_New for templates) and remove in the Document_Close events.

I have written a number of documents like that with personalised menu options and/or toolbars and they work well.  The only issue is when/if Word or the document crashes say you may end up with the toolbar or menu item left in place.  This would then remov itself next time the document was closed (i.e. re-open and close again).

The above site gives some good example code.  If you need any more I'm sure one of us can post some.

Steve
0
 
LVL 1

Expert Comment

by:MacroWizard
ID: 8043555
The only thing you have to worry about is making sure the toolbar is visible. To do that create an autoopen macro:

sub autoopen()
dim oBar as CommandBar

For Each oBar In CommandBars
    With oBar
        If .name = "ABC" Then
            If .Visible = False Then
                .Visible = True
            End If
        End If
    End With
Next

End Sub

You can also adjust the positioning of the toolbar, etc.
0
 

Author Comment

by:thartin
ID: 8064555
Okay, I think I've decided on using a popup toolbar.  (I decided against the buttons because if the document is printed through the normal print commands the buttons will show up)

I've got the code from the site dragon referenced, but I'm a novice at all this VB stuff-- where do I put it?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8068135
Press ALT F11 and you are in the VBA editor.  You should have a Project Explorer window.  If not you can press Control R or get to it from the View menu.

This lists the templates and documents that are currently open.  The one you are interested in is ThisDocument.  If you double click into that you've got the area for code relating to just this document.  You can do other stuff like organise code into Modules etc. but for now just put the code into here...

You will see two menus, change the first to read Document and in the second you can choose various events to do with the document.  The ones interested here are probably Open, Close, and New.

When you choose each it creates a skeleteon procedure for you and you can type or paste code inbetween.

In this case you would probably want code to add a toolbar or command button using in the Document_Open event and the code to remove it in Document_Close.

See how you get on with that and let us know any more issues.

Steve
0
 

Author Comment

by:thartin
ID: 8090053
I added the code from the link into the Document - Open section and it works well.  Except now I need some code to make it go away on document close too, since I now have about six of my new menus in Word :o.

Also, is there a way to make this a floating toolbar instead of a menu?
0
 
LVL 1

Accepted Solution

by:
MacroWizard earned 800 total points
ID: 8090183
For toolbars, in Word, choose Tools, Customize, Toolbars, New button and name the toolbar. To assign your print macro to it, click on the Commands tab in the customize dialog box. Under Categories, scroll down until you see macros, then select it. In the Commands box on the right, scroll down until you see your print macro (sometimes it is very hard to see the full name of your macro). Click and drag it to your new toolbar and voila! Now right click on the macro on the toolbar and change the presentation on the toolbar. If you can't decide which macro is the right one, drag it to your toolbar anyway. Then you can see the full text and decide if it is correct. If it is wrong, click and drag the button off the toolbar and just let go of your mouse once the button is off the toolbar.

To show the toolbar, in the VB Editor:
(substitute the neame of your toolbar for ABC, please include the quote though.)

Private Sub Document_Open() OR
Private Sub Document_New()
dim oBar as CommandBar

For Each oBar In CommandBars
   With oBar
       If .name = "ABC" Then
           If .Visible = False Then
               .Visible = True
           End If
       End If
   End With
Next

End Sub

To hide the toolbar, in the VB Editor:

Private Sub Document_Close()
dim oBar as CommandBar

For Each oBar In CommandBars
   With oBar
       If .name = "ABC" Then
           If .Visible = True Then
               .Visible = False
           End If
       End If
   End With
Next

End Sub

Good luck!
0
 

Author Comment

by:thartin
ID: 8113574
MacroWizard, that works just like I need it to :).  Thanks to you and all the experts (especially dragon) who helped put together the solution for me.

thartin
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question