• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

Adding a "print" button to a Word document

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
thartin
Asked:
thartin
  • 5
  • 5
  • 3
  • +1
1 Solution
 
Steve KnightIT ConsultancyCommented:
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
 
MandyCCommented:
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
 
Steve KnightIT ConsultancyCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
thartinAuthor Commented:
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
 
MacroWizardCommented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
thartinAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
MacroWizardCommented:
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
 
thartinAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
thartinAuthor Commented:
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
 
MacroWizardCommented:
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
 
thartinAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now