Att: Helmut Weber:Problems with adding CollapseEnd to my macros.

D

Dave Neve

Hello

In adding your advice about collapsing some days ago, I noticed that my
macros started to have another problem in that the cursor suddenly started
to appear infront of the * that I add to some words to show that they have
short vowels.

I tried to correct it myself until the point where I no longer know where I
am and all my macros are different.

In other words, I've confused myself so much that I no longer know my arse
from my elbow if you will excuse the expression.

Could I please give you two macros to look at, one for short vowels and one
for short rising vowels.

If you can get them to work again so that the cursor is after the * (and
preferably with a space between the * and the cursor, I will try to
incorporate the trick into the rest of my macros)

Really sorry.



Sub MidShort()
Dim wordrange As Range, lrange As Range
Set wordrange = Selection.Range
Set lrange = wordrange.Duplicate
lrange.Collapse direction:=wdCollapseEnd
lrange.InsertAfter "* "
wordrange.Font.Color = wdColorSeaGreen
lrange.Font.Color = wdColorSeaGreen

Selection.Collapse direction:=wdCollapseEnd

Selection.ExtendMode = False
Selection.Font.Reset

End Sub

____________________________________________________________________________
___________________

Sub FallingShort()

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range

j = 2
For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)

If Selection.Characters.Count <= 4 Then
lrange.Font.Size = 18
lrange.Font.Size = lrange.Font.Size - j
j = j + 2
wordrange.Font.Color = wdColorSkyBlue

Else

lrange.Font.Size = 18
lrange.Font.Size = lrange.Font.Size - j
j = j + 1
wordrange.Font.Color = wdColorSkyBlue

End If
Next i

lrange.InsertAfter "* "
lrange.Collapse direction:=wdCollapseEnd

Selection.Collapse direction:=wdCollapseEnd

Selection.ExtendMode = False
Selection.Font.Reset

End Sub
 
H

Helmut Weber

Hi Dave,
if I understand you right, according to the first
macro, it should apply a color to a word, insert
"* " after the word in the same color and reset,
so to speak, the cursor's color to standard values.
This would be required, if you want to continue typing.
Therefore I'd say, performance is not relevant here,
and so I arrive at a rather simple macro, that runs
without any variable.
---
Sub MidShortTest()
' select word in the selection
' I assume that the cursor is collapsed
With Selection
.Words(1).Select
' if the selection of the current word
' includes a space at the end
' shrink the selection
If Right(.Text, 1) = " " Then
.MoveLeft Count:=1, Extend:=wdExtend
End If
' set the color of the word
.Font.Color = wdColorSeaGreen
' which is now the color of the cursor, too
.Collapse direction:=wdCollapseEnd
' color is inherited from the cursor
.TypeText Text:="* "
.Collapse direction:=wdCollapseEnd
.ExtendMode = False
.Font.Reset
' color of the cursor is default value again
End With
End Sub
 
D

Dave Neve

Hi

Ok. Without worrying about the second macro for the moment, I am
concentrating on the macro you have just given me.

The only thing I had to do was add an underline command for the low tones
(and change the colour)

Therefore I now have the macro below but there is still a problem. Although
the colour of the font doesn't extend itself into the next word, the
underline part does (and the next word may well be a high tone)

I don't know what to say. Every time I change or add sth there is an
unexpected knock on effect and I have to go back to the help pages which
aren't easy.

But I am not a programmer and I cannot devote more time to VB until the next
hols when I hope to read the help pages extensively.

In the meantime, I'd be grateful if you could show me how to insert
'underline' and not have it extend itself after the word.



Sub Underline()



'
' MidShort Macro
' Macro créée le 24/08/2004 par Dave Neve
'Sub MidShortTest()
' select word in the selection
' I assume that the cursor is collapsed
With Selection
.Words(1).Select
' if the selection of the current word
' includes a space at the end
' shrink the selection
If Right(.Text, 1) = " " Then
.MoveLeft Count:=1, Extend:=wdExtend
End If
' set the color of the word

.Font.Underline = wdUnderlineSingle
.Font.Color = wdColorSeaGreen
' which is now the color of the cursor, too
.Collapse direction:=wdCollapseEnd
' color is inherited from the cursor
.TypeText Text:="* "
.Collapse direction:=wdCollapseEnd
.ExtendMode = False
.Font.Reset
' color of the cursor is default value again
End With
End Sub
 
H

Helmut Weber

Hi Dave,
by calling your macro "underline", you overwrite
the built in underline-macro. Check it by klicking
on the underline icon in the formatting toolbar.
What we have got so far, seems to behave different,
when run step by step [F8] and when run by [F5] or
still better by extras, macros, macro. In single-step
mode the cursor seems to vanish from the doc.
That's when font.reset seems to fail.
Looks like a minor bug to me.
Sub Underline()
' ????????????
With Selection
.Words(1).Select
If Right(.Text, 1) = " " Then
.MoveLeft Count:=1, Extend:=wdExtend
End If
.Font.Underline = wdUnderlineSingle
.Font.Color = wdColorSeaGreen
.Collapse direction:=wdCollapseEnd
.TypeText Text:="* "
.Collapse direction:=wdCollapseEnd
.ExtendMode = False
.Font.Reset
End With
End Sub
 
D

Dave Neve

Hi

Typical that I have to come across a minor bug but yes, on my computer the
font reset line works as far as colour is concerned but the underline
command extends itself up to the next word (fills the space) but doesn't
actually go as far as to underline the next word.

This is what I was trying to eradicate but without success.

However, I can live with it.

Thanks for everything. I'll tackle the rest later.
 

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