Login

User name:
Password:
Forgot User name / Password?

Register (Free)

Please take a minute to read our privacy policy.
 
Login or register
About | Contact | Blog | Site map
 

(Continued)

A small toolbar will appear.

The recording has started.

The square is used to end the recording, and the pause button (double bars plus the dot), is used to pause the macro. When there are actions that you need to do and that you do not want to record in the macro, click on pause, do your stuff, and when you are ready to continue recording, click back on that button.

Do the sequence of actions you worked out before: Shift+end; Ctrl+I; Ctrl+u; Alt+t,l,l; arrows; Enter. When you are done, press the square to end recording.

Now, go to the beginning of the next line, and press Alt + w. You will see all the line change to italics, underline, and the language attribute will be the one that you selected. Now, you can apply this macro to any line you want simply by pressing Alt + w.

This is a quick and dirty example of a macro, but whenever you have repetitive tasks, you will find it very useful to record it as a macro. From here on, it’s doingness that will help you to learn what you can or can not do with recording macros.

You can delete a macro (like the test macro we just did) by going to Tools/Macros/Macros (or Alt + F8). Select your macro on the list and press “Delete”.

You can also view the code of your macro by clicking “Edit”. You will see, it is rather easy to understand.

[Continued below]

 

Here is the code for the macro test:

Sub test()
'
' test Macro
' Macro recorded 13/06/2003 by Sylver
'
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Italic = wdToggle
If Selection.Font.Underline = wdUnderlineNone Then
          Selection.Font.Underline = wdUnderlineSingle
Else
          Selection.Font.Underline = wdUnderlineNone
End If
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
Application.CheckLanguage = True
End Sub

As you can see, this macro does not exactly “underline”. It underlines IF there was no underline, but if the selection was already underlined, it would remove it!

Position the cursor at the beginning of the line again and run the macro again. (Alt + w). Indeed, the underline disappears.

We wanted to underline the selection, no matter what, so we can correct the code a little bit:

Sub test()
'
' test Macro
' Macro recorded 13/06/2003 by Sylver
'
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Italic = wdToggle
Selection.Font.Underline = wdUnderlineSingle
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
Application.CheckLanguage = True
End Sub

Actually, just the bold line was enough to do the job. (In regular English, it says “Set the underline attribute of the font property for the selection to a single underline)

Try it, and you will see that the underline stays, whether there was one before or not. However, as you may have noticed, the italics do change back and forth. This is because it uses the command “wdToggle”.

We wanted a macro that would assign italics at all times. Now, open again the Editor, (Alt + F8, select your macro and click edit, or open the visual basic editor with Alt + F11)

Right click on “wdToggle”, and select “list Properties/methods”. This will display the list of properties or methods available for that command. Instead of assigning a toggle to the Italic attribute, we want to apply italics. Browse through the available properties until you find “wdItaly”. Click on it. Your code should now look like this:

Sub test()
'
' test Macro
' Macro recorded 13/06/2003 by Sylver
'
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Italic = wdItaly
Selection.Font.Underline = wdUnderlineSingle
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
Application.CheckLanguage = True
End Sub

If you run it, you will see that it will apply italics and underlines consistently instead of toggling them on and off.

This is not too difficult. If you want to implement someone else’s macro, you can do so by recording an empty macro, opening the Editor, and pasting the macro there.

Anyway, that’s all for now. It’s up to you to play with it and learn. The macro language is called VBA, Visual Basic for Applications, and can do many things which you can not do directly in Word.

I will post more examples of macros as the time goes by. If you have examples of useful macros, especially with explanations, send it to me and I will include it in those pages, or eventually create a macro “pool” to gather useful *free* macros.

 

                   Previous<<1  2