overlining characters

J

Jack Sons

Hi all,

Long ago I found a macro (see below) for overlining characters, but it never
worked. When executed a box pops up in which the to be overlined character
is to be typed. When I type, say, M the result is not an overlined M but "M"
followed by "," and after that a kind of opposite of underscore, what I
would call overscore. That combination is one "thing" that is marked in grey
(highlighted). It appears to be the representation of a field:
{EQ\o(M,{EQ \s\up 10(_)})}

I use XP SP2 with W2K

Anybody who knows wat goes wrong or how the macro should be corrected?

Jack Sons
The Netherlands

--------------------------------------------------------------------------------------

Sub Overline()
Dim sChar As String

sChar = InputBox("Enter character to overline", "Overline")

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="EQ \o(" + sChar + ",)"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="EQ \s\up10(_)"
Selection.Fields.ToggleShowCodes
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.Fields.ToggleShowCodes
End Sub
 
J

Jack Sons

Suzanne,

The suggestions you anf Greg gave me didn't work, finally I got it: the
comma should be a semi colon because that is the way my European version of
Word and VBA works.

I changed the ortiginal code into what you see below. My variable "keer" is
equal to the number of characters I put in the message box. I need as much
alt+0175 characters in succession to overbar this whole group of characters.
Please show me the additional code that I need.

Second question: normally with ctr+6 I can change a field into normal text,
but that will not function with the result of the overlining macro. Any
solution?

TIA.

Jack.
---------------------------------------------------------------------------------------
Sub Overline()
Dim sChar As String
Dim keer As Integer

sChar = InputBox("Enter character to overline", "Overline")
keer = Len(sChar)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="EQ \O(" + sChar + ";¯)"
'Selection.MoveLeft Unit:=wdCharacter, Count:=1
'Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
' PreserveFormatting:=False
'Selection.MoveLeft Unit:=wdCharacter, Count:=1
'Selection.Delete Unit:=wdCharacter, Count:=2
'Selection.TypeText Text:="¯"
'Selection.TypeText Text:="EQ \s\up10(_)"
Selection.Fields.ToggleShowCodes
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.ToggleShowCodes
End Sub

-----------------------------------------------------------------------------------------------
 
S

Suzanne S. Barnhill

Instead of using the overbar character, use the EQ \x field to draw an
overline over the entire word.
 
J

Jack Sons

Suzanne,

Below you see two results with their preceding code. In the first one the
bar (repeated alt+0175) has the right width but stands too low, in the
second one the bar (result of EQ \x\to) is a little bit wider than in the
first (is too wide) but its height above the characters is just what I want.

1) How can I (with code) lift the repeated alt+0175 bar in the first code
somewhat?
2) How can I transpose the field into regular text, like I can do with
ctr+6 which transforms for example a date field into real text.
3) The select case method is clearly very unsophisticated. Can you show
me better code?

I am looking forward to your answer.

Jack.

-------------------------------------------------------------------------------------------------
Sub Overline()
Dim sChar As String
Dim keer As Integer

sChar = InputBox("Enter character to overline", "Overline")
keer = Len(sChar)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Select Case keer
Case 1
Selection.TypeText Text:="EQ \O(" + sChar + ";¯)"
Case 2
Selection.TypeText Text:="EQ \O(" + sChar + ";¯¯)"
Case 3
Selection.TypeText Text:="EQ \O(" + sChar + ";¯¯¯)"
Case 4
Selection.TypeText Text:="EQ \O(" + sChar + ";¯¯¯¯)"
End Select
Selection.Fields.ToggleShowCodes
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.ToggleShowCodes
End Sub

----------------------------------------------------------------------------------------
Public Sub OverBar()
Dim Expr As String
Expr = InputBox("Enter the text to overbar:", "overbar")
If Expr <> "" Then
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _
Text:="EQ \x\to(" & Expr & ")", PreserveFormatting:=False
End If
End Sub
 
S

Suzanne S. Barnhill

I don't see any results (this is plain text), but you can raise the overbar
(Alt+0175) the same way you raise any other text, by selecting it and using
Format | Font | Character Spacing: Raised. I am VBA-ignorant, so I can't
tell you how to do any of this in code. I suggest you post your question in
one of the Word VBA NGs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top