Computer geek, and self-appointed know-it-all, Westley Annis answers all those hard 

questions about anything related to computers and technology, as well as business and 

political questions.

How can I add an EXE file to a Word toolbar?

How can I create a button in Word to launch a custom application?

Microsoft Word is a very powerful and flexible program, especially when it comes to it toolbars or CommandBars, as Microsoft refers to them.

There are two different methods of creating having a button point to an outside program. One is by using a hyperlink and the other is by using a Visual Basic for Applications (VBA) macro. Both are simple to the do and the only difference is in how the external program is called, which also changes how Word reacts in regards to security.

When using a hyperlink, Word treats it as coming for an unknown source and will display warnings asking if you really want to launch the program. It's the same as when you click on a EXE file from inside Internet Explorer, a warning displays telling you of the dangers of using an unknown program.

With a VBA macro, all the security settings are based on the trustworthiness of the macro itself. Once you allow the macro to run, everything it does is deemed to be safe, so the external program will launch with no warnings.

Safety issues aside, I'm going to focus on the VBA method since I think most folks would only be adding an EXE to their Word toolbar that they already trust and would become annoyed with the extra warnings rather quickly. Also, although I'm using Word here, these steps can be repeated in just about every other Microsoft Office application.

The steps outlined are for Word 2003 and may vary slightly for other versions of Word.

    Step 1: Create a VBA macro to launch the external program (Notepad.exe for this example)
  1. Click Tools->Macro->Macros

  2. Type "RunNotepad" and click Create

  3. Enter the following inside the VBA editor, the Sub and EndSub lines are entered automatically by the VBA editor


  4. Sub RunNotepad()
    Shell Pathname:="C:\WIndows\Notepad.exe", _ WindowStyle:=vbNormalFocus
    End Sub

  5. Close the VBA editor by clicking on the Close button


    Step 2:Add the new macro to the toolbar
  1. Click Tools->Customize

  2. Select the Commands tab.

  3. Under Categories, scroll down and select Macros.

  4. Under Commands, find the name of your macro and drag it to the Toolbar and position it where you want.

  5. Right-click on the new button you've just created (it's going to be all text) and select either "Edit Button image" to draw your own button or "Change Button image" to select a pre-drawn image.

  6. Click Close after working with your button image and your all done.

The Shell command supports several different options for how the external program is opened. View the VBA help file for more information.

Category is Microsoft Office   (Article #3)
Comments
This site is incredible!
This site is incredible! It's amazing the questions you get asked and you always come up with the answer. I've just got to help you stay cool by buying you a Snoball!
I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited
email, period. I hate it just as much as you do.

Also note that by submitting a question or comment
you're agreeing to relinquish any subsequent rights of
ownership to your material by submitting it on this site.









Ask Westley your question on technology, business, or politics!
RDF XML
Add to My Yahoo!
Subscribe in 
NewsGator Online
Feedburner
Search



All Categories
Archives by Category
Book Links
Powered by
Movable Type 3.17
© 2005 by Westley Annis. All Rights Reserved.

Valid XHTML 1.0!