Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a horizontal bar above a letter 3

Status
Not open for further replies.

aldi07

MIS
Jun 22, 2010
100
CA
Hi,
I am trying to create a function in Word 365 to add a horizontal bar above a letter.
I used a record macro, and succeeded for the first attempt only.
The first time I use it, it works:
¯A
(it does'nt appear correctly here, but in word, the bar is just above the letter "A")

But if I try it again, I get:

Run-Time error'5941':
The requested member of the collection does not exist.

Code:
Sub BarTop()
'
' BarTop Macro
' Add a horizontal bar above a letter
'
    [highlight #FCE94F]Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionBar).Bar _
        .BarTop = True[/highlight][highlight #FCE94F][highlight #FCE94F][/highlight][/highlight]
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Font.Italic = wdToggle
    Selection.Font.ItalicBi = wdToggle
    Selection.OMaths(1).ParentOMath.Justification = wdOMathJcLeft
End Sub

Could anyone help me generalise this macro?
Thank you.
 
Are you taking about “macron” or a 'Vinculum'?
AaAa_dluxsn.png


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi Andy,
I want to be able to add a bar over a letter from time to time. I presume it is called a "macron".
Alex
 
This should give you an A with a line above it:

Code:
Sub InsertA_macron()
    Selection.InsertSymbol Font:="Arial", CharacterNumber:=[red]256[/red], Unicode:=True
End Sub

and I am sure you can pass a different CharacterNumber(s) to get other letters as well

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Thank you for your answer Andy.
Yes, it works, but that's not exactly what I need.
I need, while typing a text, to type at any point of time, any letter, with a line above it (as if I was using an accent for example).
If I use your suggestion, I will have to use 26 shortcut keys, one for each letter of the alphabet.
 
A macron is a diacritic ¯ placed over a vowel. It is usually used in pronunciation guides as an indication that the vowel has a long sound. A vinculum is a bar ¯ placed over any letter or number. It is used in mathematical notation, most commonly to indicate a repeating decimal. Some fonts support macrons, but others do not. Strictly speaking, none support vinculums.

In Word, perhaps the simplest method for upper-case macrons is to type the character requiring the macron (eg X), then type 0305, so you end up with X0305, then select the 0305 and press Alt-X. With that, you should get a bar over the X. For lower-case characters (eg i), you can use 0304, and get With that, you should get a bar over the i. For double bars over a character, you can use 033F (the gap between the double lines may be indistinct over some letters).

Word fields can also be used to place a diacritic over any letter, and can thus be used for macrons and vinculums alike:
• use a field coded as {EQ \x\to(a)}. This solution increases the vertical spacing for the affected line (which you could get around by reducing the field’s point size).
• use a field coded as {EQ \o (-,a)}. To achieve the desired result, superscript the first character in the field and subscript the second character, which leads to small characters for both (which you could counter by increasing the point size), but this too increases the vertical spacing for the affected line … Note: if you have more than one subscripted character, you’ll need to compensate by increasing the # of superscripted characters and there’ll invariably be gaps between them.
• use a field coded as {EQ \s\up6(\f(,a))}. Compared to the other solutions, this one has the advantage of retaining the character sizes without increasing the line height. The ‘6’ in the formula controls the bar height.
In each example, replace the ‘a’ in the field with the desired character(s).

Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.

The following macro implements the last of the above examples for a selected string:
Code:
Sub Overline()
Dim StrTxt As String
ActiveWindow.View.ShowFieldCodes = True
With Selection
	StrTxt = .Text
	.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
		PreserveFormatting:=False, Text:="EQ \s\up6(\f(," & StrTxt & "))"
	.MoveLeft wdCharacter, 2
	.Delete
	.Fields.Update
End With
ActiveWindow.View.ShowFieldCodes = False
End Sub
Note: The field contents must fit on one line. If there's a word-wrap in the selected range, the field will force all of it onto the one line and, if the string spans more than one line, the field will display 'Error!'.


Cheers
Paul Edstein
[Fmr MS MVP - Word]
 
Hi Paul,
It works beautifully.
Thank you so nuch!
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top