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?

Question asked on July 24, 2005 11:30 PM :: :: Comments (0) :: TrackBacks (1)

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.

Categories

1 TrackBacks

Listed below are links to blogs that reference this entry: How can I add an EXE file to a Word toolbar?.

TrackBack URL for this entry: http://www.askwestley.com/cgi-sys/cgiwrap/wannis/managed-mt/mt-tb.cgi/3

» Salons St. Louis from Hair Salons St. Louis

Excellent thread, I saw this really great thread today and I wanted to link to it. Thanks again for taking the time to post. Read More

Leave a comment




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



All Categories
Powered by
Movable Type 4.1
© 2005-2009 by Westley Annis. All Rights Reserved.

Valid XHTML 1.0!