Etudes for Microsoft Word Programmers

Home ] Up ] Etude 1.1. Text Fit ] Etude 1.2. Symbol Case ] Etude 1.3. Finding and Painting Hyperlinks ] Etude 1.4. Styles ] Etude 1.5. Inserting Formatted Text ] Etude 1.6. Text in the Column. ] Etude 1.7. Formatting Headline. ]


Etude 1.2. Symbol Case

The term case comes from the printing trade when the use of moving type was invented in the early Middle Ages (Caxton or Gutenberg?) and the letters for each font were stored in a box with two sections (or "cases"), the upper case was for the capital letters and the lower case was for the small letters. The Oxford Universal Dictionary of Historical Principles (Feb 1993, reprinted 1952) indicates that this usage of "case" (as the box or frame used by a compositor in the printing trade) was first used in 1588.

http://www.websters-online-dictionary.org/definition/Case

Realization of some operations requires several actions. For instance, these sequence of actions should be performed to change the symbol case:

  • 1. choose "Format\Change Case..." in the menu or push the corresponding button on the toolbar

  • 2. choose the necessary operation in the dialog "Change Case"

  • 3. push “OK”

If you need the operation frequently it is a fine candidate for the creation of macros and the appearance of the corresponding button on the toolbar. Let the computer work for us!

Resources

Template "AhTextCase.dot", 18 Kb, ZIP [download].

Functional Specification

Task

Create the template "AhTextCase.dot" with all macros for changing the symbol case and the toolbar "AhTextCase", which provides fast and convenient access to all these macros.

Toolbar "AhTextCase"

The toolbar "AhTextCase" looks like this:

 

The toolbar "AhTextCase" provides access to the following functions.

Button

Macros

Description

Help

AhTextCaseAbout

Brief prompt of the buttons of the toolbar.

Upper

AhTextCaseUpper

Transfer of the selected text to the Upper Case.

Lower

AhTextCaseLower

Transfer of the selected text to the Lower Case.

Toggle

AhTextCaseToggle

Change of the selected text from Lower case to Upper case or vice versa.

Sentence

AhTextCaseSentence

Transfer of the first symbol of the selected text to the Upper case, and the rest symbols – to the Lower.

Title

AhTextCaseTitle

Transfer of the first symbol of each word of the selected text to the Upper case, and the rest – to the Lower.

Help

Brief prompt of the buttons of the toolbar looks like this:

The specification turned out to be very brief. It doesn’t matter. The thing is in complete understanding and having no problems with the task realization.

Implementation - Template "AhTextCase.dot"

Simple operations dealing with symbol case are implemented in the template "AhTextCase.dot". The toolbar "AhTextCase" is a simple interface to basic operations of changing symbol case – the transfer of the selected text to the Upper or Lower case, symbol case change and also setting the symbol case for "Sentence" and "Title".

The basic subroutine which changes the symbol case is AhTextCaseChange. The procedures AhTextCaseUpper, AhTextCaseLower, AhTextCaseToggle, AhTextCaseSentence and AhTextCaseTitle just call the AhTextCaseChange function supplying the necessary arguments.

All the source code is located in the module "AhTextCase".

'
' File AhTextCase.dot|AhTextCase
'
' Etudes for Microsoft Word Programmers.
' Etude 1.2. Symbol Case.
' First published on http://www.transcriber.ru
'
' © 2000-2007. Evgeny Akhundzhanov. All rights reserved worldwide.
'
Option Explicit

Subroutine AhTextCaseHelp

Sub AhTextCaseHelp()
MsgBox "Etudes for Microsoft Word Programmers." & vbCrLf & _
    "Etude 1.2. Symbol Case." & vbCrLf & _
    "http://www.transcriber.ru" & vbCrLf & vbCrLf & _
    "Template 'AhTextCase.dot' - " & _
    "Changing text case." & vbCrLf & vbCrLf & _
    "Upper - upper case" & vbCrLf & _
    "Lower - lower case" & vbCrLf & _
    "Toggle - toggle case" & vbCrLf & _
    "Sentence - sentence case" & vbCrLf & _
    "Title - title case" & vbCrLf & _
    vbCrLf & "All commands change selection."
End Sub

Subroutine AhTextCaseChange

'
' AhTextCaseChange
'
Private Sub AhTextCaseChange(ByVal dwCharCase As Long)
If Documents.Count = 0 Then Exit Sub
    On Error Resume Next
    Selection.Range.Case = dwCharCase
End Sub

Subroutine AhTextCaseUpper

'
' AhTextCaseUpper
'
Sub AhTextCaseUpper()
    AhTextCaseChange wdUpperCase
End Sub

Subroutine AhTextCaseLower

'
' AhTextCaseLower
'
Sub AhTextCaseLower()
    AhTextCaseChange wdLowerCase
End Sub

Subroutine AhTextCaseToggle

'
' AhTextCaseToggle
'
Sub AhTextCaseToggle()
    AhTextCaseChange wdToggleCase
End Sub

Subroutine AhTextCaseSentence

'
' AhTextCaseSentence
'
Sub AhTextCaseSentence()
    AhTextCaseChange wdTitleSentence
End Sub

Subroutine AhTextCaseTitle

'
' AhTextCaseTitle
'
Sub AhTextCaseTitle()
    AhTextCaseChange wdTitleWord
End Sub

Summary

The template "AhTextCase.dot” is created on the basis of specification in this etude. Its module "AhTextCase" contains simple macros dealing with symbol case. The created toolbar "AhTextCase" provides a fast and convenient interface to basic operations of changing symbol case.

This etude turned out to be very brief. As brief as it is possible. Therefore, firstly we got acquainted with functional specification. And, secondly, we replaced four complex operations by one button click. Indeed, you have to open the menu "Format", find the command "Change Case" and then select it. If the command is rare in use, it may be hidden and you’ll have to fully open the menu. In the dialog "Change Case" you have to choose the necessary type of case with a click and then push "OK". Now it is all replaced with one mouse click. This is what is called "the power of the computer on the fingertips".

It is interesting to know that initially the intentions were good and were aimed at hiding from a user the commands which he uses rarely. The result is awful. Habitual commands change habitual places and you have to search for them. Now they are in one place, and then – in another. In the computer at work they are situated in one place, in your colleague’s computer – in another, at home they occupy the third place.  People who work with text professionally become tired of looking at the screen in search of what should be right here. It is like looking for your personal things in your own house. Everything should have its own place. You begin to think that the commands out-of-use should be seen and your command in use should have their constant habitual place.

To switch such intellectual behavior of the user’s interface off some effort should be taken. Go to "Tools\Customize\Options" and select the checkbox "Always show full menus".

Tasks

Task 1

Analyse operations that you have to repeat every day. Arrange them according to their difficulty. Do not be in a hurry. May be it is worth beginning not with macros and toolbars, but with functional specification? Firstly it will help you to make out the task and secondly it will save a lot of precious time in perspective. It is even more useful for difficult tasks. But the matter is that we never know if the task is difficult for us or not. Some seemingly simple tasks turn out to be difficult when time passes.  In this case the specification is ideal for gathering and sifting data and listing the decisions taken. It is much more difficult to change the SOURCE than to rewrite or change some paragraphs in the text editor.

 

Task 2

The programming languages are simple in design. And VBA is not an exception. Vice versa, it is difficult to imagine a simpler programming language. General treasures of any programming language are its functions. They are situated, as a rule, in standard runtime libraries. The more functions you know the more opportunities and potencies you have.  In case with Microsoft Word standard functions have hierarchical structure called “Microsoft Word Object Model.”. The objects which are most frequently in use are: Application (Microsoft Word itself), Document (a document), Selection (selected text) and Range (the object that represents an arbitrary continuous part of any document).

Reference materials about the Microsoft Word Object Model are available on the site of Microsoft Corporation. And also in the Appendix to this book. Study or at least look through the functions and methods of the objects mentioned above.

 


Etudes for Microsoft Word Programmers. Etude 1.2.


Unless otherwise noted, all materials on this site are
© 2000-2009 Evgeny Akhundzhanov, All Rights Reserved Worldwide
Microsoft is in no way affiliated with, nor offers endorsement of, this site.
www.transcriber.ru | E-mail the Author