Cursor position and select

D

Dave Neve

Hello,

Ideally, I'd now like to build a menu a bit like Words own automatic
insertion menu and have a list of prefixes, suffixes, morphs etc so that I
don't have to type them out all the time.

It would be great if the text has letters where the font size
increases/decreases to represent rising and falling tones of the language in
question. After reading, I think I need sth like

Sub InsertAutoTextEntry()
ActiveDocument.Content.Select
ActiveDocument.AttachedTemplate.AutoTextEntries("one").Insert _
Where:=Selection.Range, RichText:=False
End Subbut I know this is not quite right. I need to select the position of
the cursor (this is where I want to insert)and somehow I have then to select
the inserted word etc and apply one of my macros like
Sub LowShort()

Dim wordrange As Range, lrange As Range
Set wordrange = Selection.Range
Set lrange = wordrange.Duplicate
lrange.Collapse Direction:=wdCollapseEnd
lrange.InsertBefore "* "
wordrange.Underline = wdUnderlineSingle
wordrange.Font.Color = wdColorBrown

lrange.Font.Color = wdColorBrown
End Sub


So, for the moment, my two questions are

1 How do you select the cursor's position?

2 How do you select the word which has just been inserted without
selecting it manually?

As for building the menu with a list of prefixes etc in the tool bar, I
think I know more or less how to do that but we'll see when push comes to
the shove.

Any help appreciated.
 
H

Helmut Weber

Hi Dave,
how about this one:
Sub Test123()
Dim r As Range ' the range of the inserted autotext
Dim l As Long ' the start of that range
Dim m As Long ' the end of that range
Set r = Selection.Range
l = r.Start
NormalTemplate.AutoTextEntries("Betreff:").Insert _
Where:=Selection.Range, RichText:=True
r.End = Selection.Range.Start
r.Font.Color = wdColorRed
End Sub
 
D

Dave Neve

Hi

Thanks for the try but there is a '5941 error' on two consecutive lines when
I try to run it (starting on line 'Normal Template'

What's more, I see that you declare 'm' as Long but it is never used in the
code.

Something escapes me here.

Please could you explain this?

Thanks in advance

Dave Neve
 
H

Helmut Weber

Hi Dave,
Dim m As Long ' the end of that range
forget it, it is not required anymore.
It used it during design time.
Error 5941:
You don't have an autotext entry "Betreff:", I guess.
By the way, it is german for "topic".
 

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