Problem with simple code

D

Dave Neve

The following code gives me gap*

but what I want is gap*

How is it done please?

Thanks in advance

Sub LowShort()

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range
For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)
Selection.Range.Font.Size = 10
Selection.Range.Underline = wdUnderlineThick
wordrange.Font.Color = wdColorBrown
Next i
Selection.Collapse Direction:=wdCollapseEnd
Selection.TypeText Text:="*"
End Sub
 
D

Doug Robbins - Word MVP

I cannot see any difference between what you are getting and what you want.

As far as your code is concerned, I can't see what the purpose of the For
Next loop or for setting Irange to each succeding character in the range.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Dave Neve

Hi

Sorry but OE mucked up the underline and there was no visible difference
between the two examples.

The first one is underlined comletely while in the second one only the
letters and asterisk are underlined (not the space in between)

Thanks
 
D

Doug Robbins - Word MVP

Does this do what you want:

Dim wordrange As range, lrange As range
Set wordrange = Selection.range
Set lrange = wordrange.Duplicate
lrange.Collapse wdcollapsend
lrange.InsertBefore " *"
wordrange.Underline = wdUnderlineThick
wordrange.Font.Color = wdColorBrown
lrange.Start = lrange.Start + 1
lrange.Underline = wdUnderlineThick
lrange.Font.Color = wdColorBrown

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Dave Neve

Hi

The code didn't work at first but I managed to understand it and change the
4th line a bit and hey presto!!!

Thanks a million for the support.
 
D

Doug Robbins - Word MVP

Hi Dave,

Of course, wdcollapsend should have been wdCollapseEnd


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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