Monday, August 2, 2010

Assigning a Macro to a Shortcut Key:-

Word allows you to assign macros or commands to specific key combinations. These key combinations are referred to as shortcut keys, and when used they result in the macro or command being executed. When you first create a macro by recording it, Word gives you the opportunity to assign the macro to a specific key combination. If you later want to change the key combination, you can follow these steps:

1. Select Customize from the Tools menu. You will see the Customize dialog box.
2. Click on the Keyboard button. Word displays the Customize Keyboard dialog box. (Click here to see a related figure.)
3. Scroll through the Categories list and select the Macros category. The list at the right side of the dialog box changes to show the currently available macros.
4. In the Macros list, select the macro you want assigned to the shortcut key.
5. With the insertion pointer in the Press New Shortcut Key box, press the shortcut key you want to use. For instance, if you want to use Ctrl+Alt+J, press that.
6. Just below the Press New Shortcut Key box you can see whether the shortcut key is already assigned to a different function.
7. Click on Assign.
8. Repeat steps 4 through 7 for each change you want to make.
9. Click on Close.

Aligning a Paragraph in a Word Macro:-

Word allows a rich set of formatting attributes for text in a document. You can control the alignment of a paragraph by using the following VBA statement:

Selection.Paragraphs.Alignment = position

where position is one of the constants shown in the following table:-

Constant Result
wdAlignParagraphLeft Formats the current paragraph as left justified
wdAlignParagraphCenter Formats the current paragraph as centered
wdAlignParagraphRight Formats the current paragraph as right justified
wdAlignParagraphJustify Formats the current paragraph so it expands to the left and right margins

Adding a Macro to a Toolbar:-

For instance, you can create a macro, and then add it to a toolbar. How you do this depends on which version of Word you are using.

If you are using a version of Word prior to Word 2007, then follow these steps:

1. Choose Customize from the Tools menu. Word displays the Customize dialog box.
2. Make sure the Toolbars tab is selected. (Click here to see a related figure.)
3. In the list of toolbars, make sure there is a check mark beside the toolbar to which you want your macro added. The check mark ensures that the toolbar is displayed on the screen.
4. Click on the Commands tab.
5. In the list of Categories, choose the Macros entry. Your macros should then appear in the Commands list.
6. In the Commands list, select the macro you want assigned to a toolbar.
7. Using the mouse, drag the macro from the Commands list to the location on the toolbar where you want it to appear.
8. When you drop the macro, it appears on the toolbar.
9. To add more macros, repeat steps 6 through 8.
10. Click on Close.

Word 2007 is different; it doesn't technically have toolbars like older versions of Word had. You can't make additions or changes to the ribbon, but you can add macros to the Quick Access toolbar. Follow these steps:

1. Click the Office button and then click Word Options. Word displays the Word Options dialog box.
2. At the left side of the dialog box, click the Customize option.
3. Using the Choose Commands From drop-down list, choose Macros.
4. In the list of available macros, select the one you want assigned to the Quick Access toolbar.
5. Click the Add button. The command now appears at the right side of the dialog box.
6. Click the OK button. The command now appears on the Quick Access toolbar.

Accessing Objects in a Word Project:-

When you create a new application-level project for Word by using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO 2005 SE), Visual Studio automatically creates a ThisAddIn.vb or ThisAddIn.cs code file. You can access the Application object by using Me.Application or this.Application.

When you create a new document-level project for Word by using VSTO 2005, you have the option of creating a new Word Application or Word Template project. VSTO 2005 automatically creates a ThisDocument.vb or ThisDocument.cs code file in your new Word project for both Document and Template projects. You can access the Application and Document objects by using the Me or this object reference.

At first glance, there appears to be a lot of overlap in the Word object model. For example, the Document and Selection objects are both members of the Application object, but the Document object is also a member of the Selection object. Both the Document and Selection objects contain Bookmark and Range objects. The overlap exists because there are multiple ways you can access the same type of object. For example, you apply formatting to a Range object; but you may want to access the range of the current selection, a particular paragraph, section or the entire document.

The Application object contains the Document, Selection, Bookmark, and Range objects.

Word provides hundreds of objects with which you can interact. The following sections briefly describe the top-level objects and how they interact with each other. These include:

1. Application object
2. Document object
3. Selection object
4. Range object
5. Bookmark object

Object model:-

In computing, object model has two related but distinct meanings:

The properties of objects in general, in a specific computer programming language, technology, notation or methodology that uses them. For example, the Java object model, the COM object model, or the object model of OMT. Such object models are usually defined using concepts such as class, message, inheritance, polymorphism, and encapsulation. There is an extensive literature on formalized object models as a subset of the formal semantics of programming languages.
A collection of objects or classes through which a program can examine and manipulate some specific parts of its world. In other words, the object-oriented interface to some service or system. Such an interface is said to be the object model of the represented service or system. For example, the Document Object Model (DOM) [1] is a collection of objects that represent a page in a web browser, used by script programs to examine and dynamically change the page. There is a Microsoft Excel object model [2] for controlling Microsoft Excel from another program, and the ASCOM Telescope Driver [3] is an object model for controlling an astronomical telescope.