using vba to automatically open toolbar in word document

J

JayM

I have created a document for users which needs to be totalled. For ease I
have created a calculator button in a toolbar.

How can I get to toolbar to open automatically when the document is opened.
(preferably I do not want the toolbar to be closed until the document is
closed).
 
S

Stephanie Krieger

Hi, Jay,

What you want to do is no problem.

All you need is a little Document_Open event macro in the
document's "ThisDocument" code. A Document_Open event
automatically runs every time the document is opened. You
can also ensure that the toolbar isn't visible when the
document is not open (this is only necessary if you
didn't create the toolbar as attached to the document
itself) by adding a Document_Close event. They have to be
placed in the ThisDocument code in order to work
automatically.

Here's the code for both:

Sub Document_Open()

ActiveDocument.CommandBars("toolbar name").Visible = True
ActiveDocument.CommandBars("toolbar name").Protection =
msoBarNoChangeVisible

End Sub

Sub Document_Close()

ActiveDocument.CommandBars("toolbar name").Visible = False
ActiveDocument.CommandBars("toolbar name").Protection =
msoBarNoChangeVisible

End Sub


Hope that's helpful.

Best,

Stephanie Krieger
author of Microsoft Office Document Designer (from
Microsoft Learning)
email: MODD_2003 at msn dot com
blog: arouet.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top