What is macros and what is it used for?

  • Thread starter Thread starter Hutch2020
  • Start date Start date
The first place to start should be the Help files. Then I would suggest
using Google or Bing. You will find a wealth of information that way.
 
Hutch2020 said:
I have never used macros and would like to know what it is and what it is
used for.

They are used to automate actions in Word, such as repetitive
keystrokes, actions.

I use them to copy data between documents or into documents.

They are very powerful because they use VBA (Visual Basic for
Applications), which is a scripting language.

hope this helps
 
at453 said:
They are used to automate actions in Word, such as repetitive
keystrokes, actions.

I use them to copy data between documents or into documents.

They are very powerful because they use VBA (Visual Basic for
Applications), which is a scripting language.

hope this helps

Also, you might want have a look at the usenet group
microsoft.public.word.vba.general
and to
microsoft.public.word.vba.customization
and
microsoft.public.scripting.vbscript

to see some code examples and problems solved
 
Not to be snarky, but have you tried looking in the Word help or doing a web
search for the answer to this question? These resources can probably provide
you more information more quickly and easily than posting to a newsgroup.
Searching the Word help for "about macros" provides a link to a topic called
'About macros' (amongst many others), which reads:

About macros
If you perform a task repeatedly in Microsoft Word, you can automate the
task by using a macro. A macro is a series of Word commands and instructions
that you group together as a single command to accomplish a task
automatically.

Here are some typical uses for macros:

To speed up routine editing and formatting
To combine multiple commands; for example, inserting a table with a specific
size and borders, and with a specific number of rows and columns
To make an option in a dialog box more accessible
To automate a complex series of tasks
Word offers two ways to create a macro: the macro recorder and the Visual
Basic Editor (Visual Basic Editor: An environment in which you write new and
edit existing Visual Basic for Applications code and procedures. The Visual
Basic Editor contains a complete debugging toolset for finding syntax,
run-time, and logic problems in your code.).

Recording a macro

The macro recorder in Word acts like a tape recorder. It records your
deliberate keystrokes and mouse button clicks by translating them into
Microsoft Visual Basic for Applications (VBA: A macro-language version of
Microsoft Visual Basic that is used to program Windows applications and is
included with several Microsoft applications.) code. When you record a macro,
you can use the mouse to click commands and options, but not to select text.
You must use the keyboard to record these actions. For example, you can use
F8 to select text and press END to move the cursor to the end of the line.

Tips for recording macros

Before you record a macro, plan the steps and commands you want the macro to
perform.
If you make a mistake when you record the macro, corrections you make will
also be recorded. You can edit the macro later to remove unnecessary steps
you recorded.
Try to anticipate any messages that Word might display that can prevent your
macro from running.
If the macro includes the Edit menu Find or Replace commands, click More on
the Find or Replace tabs, and then click All in the Search box. If the macro
searches up or down only, Word stops the macro when it reaches the beginning
or end of the document and displays a message asking whether you want to
continue searching.
If you want to use the macro you're recording in other documents, make sure
that the macro doesn't depend on the current document's contents.
If you use a particular macro often, assign it to a toolbar button, a menu,
or shortcut keys. That way, you can run the macro directly without having to
open the Macros dialog box.
Creating macros by using the Microsoft Visual Basic Editor

You can use the Visual Basic Editor to create very flexible, powerful macros
that include Visual Basic instructions that you cannot record.

When you use the Visual Basic Editor, you can get additional assistance,
such as reference information about objects (object: A table, chart, graphic,
equation, or other form of information. Objects created in one application,
for example spreadsheets, and linked or embedded in another application are
OLE objects.) and properties (property: A named attribute of a control, a
field, or an object that you set to define one of the object's
characteristics (such as size, color, or screen location) or an aspect of its
behavior (such as whether the object is hidden).).

Assigning macros to toolbar buttons, menus, and shortcut keys

For quick access to your macro, you can assign it to a toolbar (toolbar: A
bar with buttons and options that you use to carry out commands. To display a
toolbar, click Customize on the Tools menu, and then click the Toolbars
tab.), a menu (menu: A list of commands that is displayed when you click a
menu name on a menu bar or other toolbar.), or shortcut keys (shortcut key: A
function key or key combination, such as F5 or CTRL+A, that you use to carry
out a menu command. In contrast, an access key is a key combination, such as
ALT+F, that moves the focus to a menu, command, or control.). Running the
macro is as simple as clicking the toolbar button or menu command or pressing
the shortcut keys.

If you give a newly created macro the same name as an existing built-in
command in Word, the new macro actions will replace the actions of the
built-in command. For example, if you record a new macro and name it
FileClose, it becomes attached to the Close command. When you choose the
Close command, Word performs the new actions you recorded.

Note If you do this by mistake, simply delete the newly created macro, and
re-record it under a new name. The built-in command retains the original
actions.


Storing macros

You can store macros in templates (template: A file or files that contain
the structure and tools for shaping such elements as the style and page
layout of finished files. For example, Word templates can shape a single
document, and FrontPage templates can shape an entire Web site.) or in
documents. By default, Word stores macros in the Normal template (Normal
template: A global template that you can use for any type of document. You
can modify this template to change the default document formatting or
content.) so that they're available for use with every Word document. If you
plan to use a macro in a single document, store it in that document.
Individual macros in a document are stored in macro projects (macro project:
A collection of components, including forms, code, and class modules, that
make up a macro. Macro projects created in Microsoft Visual Basic for
Applications can be included in add-ins and in most Microsoft Office
programs.) that you can copy from one document to another.

Automating tasks in Web pages

To automate a task in a Word document that you save and publish as a Web
page, instead of using a macro, you use a script anchor (script anchor: The
visual representation of a script on a Web page that you open in a Microsoft
Office program. Script anchors are not displayed by default. Different script
anchors represent scripts written in different scripting languages.) and
Microsoft Script Editor (Microsoft Script Editor: Used to add text, edit HTML
tags, and edit any Microsoft Visual Basic Scripting Edition (VBScript) code
in a data access page. You can also view your page in the Script Editor as it
would appear in a Web browser.).

Script anchors mark where you want to store a script in your Word document.
When you double-click the script anchor in the Word document, Microsoft
Script Editor starts so that you can program or edit the script. The script
runs when the Web page is displayed in the Web browser.

--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
Back
Top