Word Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Word Hacks [Electronic resources] - نسخه متنی

Andrew Savikas

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 50 Manage Macros with Templates

By default, Word stores macros in the
ubiquitous Normal template. This works fine in the short term, but
macros you plan to keep and reuse should go in a separate
template.

When you first start working
with macros, those macros will be stored
(with many of your other customizations) as part of
Word's default template,
Normal.dot. Normal.dot is
such
an integral part of Word that if you delete or rename it, Word will
create a new version of the template using default settings stored in
the program itself.

Whenever you're working in Word,
you're working with Normal.dot.
Even if a particular document is based on another template,
Normal.dot is still there, including any macros
stored in it.

Normal.dot's secret is that
it's a chameleon of a template. When you create a
new, blank document, Normal.dot functions as
that document's template, like any
other document
template
. But Normal.dot also behaves
like a global template, also referred to as an
add-in. A document can be associated with only
one document template, but many global templates may be open and
running at any given time.

Global templates are primarily used to store macros and toolbar
customizations. For example, GhostWord [Hack #23]
is a global template that adds a toolbar and provides certain macro
features used to interact with Ghostscript from within Word. Many
third-party applications are supplied as add-ins, allowing them to
add features and customizations to Word.

But why bother keeping macros anywhere except
Normal.dot? In its dual role as document
template and global template, as well as general repository for
myriad customizations, Normal.dot can log a lot
of miles in a short amount of time. The more macros that are stored
in it, the larger and slower to load it can become, which can
potentially contribute to corruption over time.


If you suspect a corrupt Normal template, try the techniques in [Hack #51] .

Many regular macro users prefer to keep their macros in their own
global template. This template can be set to load automatically, just
like third-party add-ins such as GhostWord.


5.7.1 Creating the Global Template


There are just two simple
steps to creating a global template that will load whenever Word
starts up [Hack #52] :

Create a new, blank document.

Select FileSave As and choose "Document
template" in the "Save as
type" field to save the document as a template. When
you choose to save as a template, Word automatically places you in
the templates folder, which is usually C:\Documents and
Settings\<username>\Application
Data\Microsoft\Templates.

Navigate up one directory, then back down to C:\Documents
and Settings\<username>\Application
Data\Microsoft\Word\STARTUP. Save your template in that
folder, naming it MacrosTemplate.dot or
something similarly descriptive.

The next time you start Word, the template you just created will be
listed as a loaded add-in from the Templates and Add-ins dialog
(select ToolsTemplates and Add-ins), as shown in Figure 5-9. Any other add-ins you've
installed, such as the FaceID browser Section 2.9[Hack #10]], will
also be listed.


Figure 5-9. Viewing currently loaded global templates

Even though it's not listed,
Normal.dot also acts like a global template
whenever you work in Word. If you work on a document based on
Normal.dot, then it also acts like a document
template.


5.7.2 Adding Macros to the Global Template


When a global template
is
loaded, you can't edit it. To make changes to a
global template, such as adding macros or creating a toolbar, you
must first unload it (using the Templates and Add-ins dialog shown in
Figure 5-9) and then select FileOpen and
choose the template file.

Because it takes a bit of work to open the global template for
editing, you may find it easier to create your macros in
Normal.dot and then periodically move any new
macros you plan to keep over to the global template. This is a great
habit to get into, because it also gives you an opportunity to delete
any old, unused macros.

There are two ways to transfer macros from one template to another.
First, you can select ToolsMacroMacros, click the
Organizer button, and copy the macros (along with styles, custom
toolbars, and AutoText entries) from one template to another.

The second way is to copy the macros directly from within the Visual
Basic Editor [Hack #2].
Since you'll be regularly moving your macros from
Normal to your MacrosTemplate global template, the only
module in Normal.dot should
be the NewMacros module Word inserts when you
create a macro from the Word interface. After deleting any macros you
don't want to keep (just select the code and delete
it), you can drag and drop a copy of the NewMacros
module into the MacrosTemplate template, as shown in Figure 5-10.


Figure 5-10. Copying a code module from one template to another by dragging it in the Visual Basic Editor

After copying the module, rename it using the Properties window just
below the Project Explorer. Then either delete the
NewMacros module from
Normal.dot (right-click it and choose Remove) or
clear out its contents from within the Code window.

Save and close the global template, and the next time you start Word,
your macros will be waiting.


/ 162