×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Add a horizontal bar above a letter
3

Add a horizontal bar above a letter

Add a horizontal bar above a letter

(OP)
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
'
    Selection.OMaths(1).Functions.Add(Selection.Range, wdOMathFunctionBar).Bar _
        .BarTop = True
    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.

RE: Add a horizontal bar above a letter

Are you taking about “macron” or a 'Vinculum'?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Add a horizontal bar above a letter

(OP)
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

RE: Add a horizontal bar above a letter

This should give you an A with a line above it:

CODE

Sub InsertA_macron()
    Selection.InsertSymbol Font:="Arial", CharacterNumber:=256, 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

RE: Add a horizontal bar above a letter

(OP)
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.

RE: Add a horizontal bar above a letter

3
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]

RE: Add a horizontal bar above a letter

(OP)
Hi Paul,
It works beautifully.
Thank you so nuch!
Alex

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close