Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 30
نمايش فراداده

Hack 9 Tweak the New Document Task Pane

The jury's still out on the Task Pane introduced in Word 2002, and poor documentation along with bad behavior has only hurt its case. This hack offers some tips on taming the worst offender: the New Document pane.

Many users find the New Document pane a welcome relief from the clutter of the Templates dialog, which is packed with obscure tabs (as shown in Figure 2-18). Othersparticularly those who use many different templatesabhor the extra step needed to get to the Templates dialog, now that the Task Pane comes first. But like it or not, you expect the Task Pane to behave as advertised. Yeah, right.

Figure 2-18. The Templates dialog grows more crowded with each release

2.8.1 Disabling the Task Pane When Word Starts

In a perfect world, you could select ToolsOptions, click the View tab, and uncheck the "Startup Task Pane" box to disable the Task Pane. But for many Word users, this setting has absolutely no effect.

The fix is a registry hack that will put the Task Pane back in its place.

Make sure you set a system restore point before you make any changes to the registry: select StartControl PanelPerformance and MaintenanceSystem Restore (the location of System Restore may vary, depending on how you've configured Windows).

Close Word, select StartRun, and enter regedit to open the registry editor. Navigate to the following key:

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General\

Locate the subkey named DoNotDismissFileNewTaskPane and either delete it or set its value to 0.

Close the registry editor and restart Word. The Task Pane will now dutifully obey the checkbox on the View tab.

2.8.2 Add Documents and Templates to the Task Pane

The New Document Task Pane includes several default options for creating new documents, including access to templates on the Microsoft web site, as shown in Figure 2-19.

Figure 2-19. The New Document Task Pane

In addition to the two sections shown in Figure 2-19, there are two additional sections that will become visible only after you've done certain things in Word (such as creating a document based on a template other than Normal.dot). The four sections are the following:

New

Templates

Recently used templates

Other files

In addition to templates, the "Recently used templates" section contains any documents on which you've recently based a new document.

In VBA, you can add items to and remove items from each of the four sections using the NewDocument property. In Figure 2-20, new documents (with rather silly names) have been added to each section.

Figure 2-20. The four sections of the New Document Task Pane

2.8.3 The Code

The NewDocument property has two methods: Add and Remove. The syntax for the two methods is identical. The syntax for Add follows:

Application.NewDocument.Add(FileName, [Section], _
[DisplayName], [Action]) as Boolean

The brackets imply that you need only the FileName argument, but if you omit the DisplayName argument, you will not actually add anything to the Task Pane. You will, however, gunk up your registry with a useless entry.

You can use the arguments for Add to specify the following information:

FileName

The actual name of the file, including the path, or a URL.

Section

The section of the New Document Task Pane where the link will appear. You can use the following four Office VBA constants (their actual values are shown in parentheses):

msoNew(1)

The "New" section

msoNewfromExistingFile(2)

The "Recently used templates" section

msoNewfromTemplate(3)

The "Templates" section

msoBottomSection(4)

The "Other files" section (default)

DisplayName

The name of the file or URL as it will appear on the Task Pane.

Action

What happens when you follow the link to the file. You can use the following three Office VBA constants (their actual values are shown in parentheses):

msoEditFile(0)

Opens the file or template for editing (default).

msoCreateNewFile(1)

Creates a new document based on the document or template.

msoOpenFile(2)

Opens the file as if it were an external hyperlink (you'll get the File Download dialog box, even for files on your hard drive). Use this option when creating hyperlinks on the Task Pane.

The following macro adds the template MyTemplate.dot to the "Templates" section:

Sub AddTemplateToTaskBar( )
Application.NewDocument.Add "c:\MyTemplate.dot", _
msoNewfromTemplate, "My Template", msoCreateNewFile
End Sub

Because the syntax for the Remove method is identical to the syntax for Add, the following macro removes the same MyTemplate.dot file from the Task Pane:

Sub RemoveTemplateFromTaskBar( )
Application.NewDocument.Remove "c:\MyTemplate.dot", _
msoNewfromTemplate, "My Template", msoCreateNewFile
End Sub

Again, note that you must include the DisplayName argument to actually remove the file from the Task Pane.

2.8.4 Hacking the Hack

If you hack with the above functions for any amount of time, you'll likely end up with a few items on your Task Pane that you just can't shake. And there's no way, using VBA, to get a list of the items currently placed there.

To do some housecleaning, you'll need to hack the registry. Choose StartRun and enter regedit. Navigate to the following key, which lists any entries you've added to the New Document pane:

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\New Document

Regardless of the FileName or DisplayName used in VBA to create the Task Pane entries, in the registry, the entries are always named Custom1, Custom2, and so on. After you delete them from the registry, they won't reappear the next time you open the New Document pane. To delete one of the entries, select it (as shown in Figure 2-21) and choose EditDelete.

Figure 2-21. Cleaning out items from the New Documents Task Pane

If you want to clean out the list of recently used templates as well, just clear the entries from the following key:

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Recent Templates

Because the registry stores Task Pane entries, you can add new ones using a .reg file. The following .reg file creates a new entry in the "Other files" section of the New Document Task Pane with a link to the O'Reilly web site, as shown in Figure 2-22:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\New Document\Custom9]
"Action"=dword:00000002
"DisplayName"="Visit oreilly.com"
"Filename"="http://www.oreilly.com"
"Section"=dword:00000004

Notice that the values for Action and Section correspond to the values described earlier in the syntax for the Add method (well, except for all the leading zeros).

Because you can easily distribute registry files across an office, this way you can add an intranet link or other useful shortcut to a user's Word workspace.

Figure 2-22. Putting an Internet hyperlink on the Task Pane

To run the .reg file, just double-click its icon.