Inserting text at a specific point via VBA?

M

ML

I am currently doing the following to insert text at a specific point and it
works fine but I'd rather just code the text directly rather than reference
an autotext entry. How can I do this in a similar fashion to below? Only
autotext seems to have the insert method.

Set a = ActiveDocument.AttachedTemplate.AutoTextEntries("ORCON")
a.Insert Where:=Selection.Range, RichText:=True
 
C

Cindy M -WordMVP-

Hi Ml,
I am currently doing the following to insert text at a specific point and it
works fine but I'd rather just code the text directly rather than reference
an autotext entry. How can I do this in a similar fashion to below? Only
autotext seems to have the insert method.

Set a = ActiveDocument.AttachedTemplate.AutoTextEntries("ORCON")
a.Insert Where:=Selection.Range, RichText:=True
ActiveDocument.Content.Text = "This is my text"

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
G

Greg

Here are a few:

Sub Test()
Selection.TypeText "Hello ML"
'or
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content 'or some other range
oRng.Text = "Hello ML"
End Sub
 
M

ML

Thanks. I should note that I also need to be able to set the font
properties. That seems to be the part I'm missing now.

Ex:
Dim fHidden As New Font
'Setup hidden font for marker
fHidden.Hidden = True
fHidden.Bold = True
fHidden.Color = wdColorOrange
a.Insert(Where:=Selection.Range, RichText:=True).Font = fHidden
 
H

Helmut Weber

Hi ML,

how about this one:

Sub test09()
Dim fHidden As New Font
fHidden.Hidden = True
fHidden.Bold = True
fHidden.Color = wdColorOrange
Dim sTmp As String
sTmp = "aaa"
With Selection
.Text = sTmp
.Font = fHidden
End With
End Sub
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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