Insert AutoText in Bookmark

M

mark

Hi,

I'm trying to insert an AutoText into a bookmark but retain the bookmark.
I've looked at previous posts and can see how to do text but can't work out
how to do it for AutoText.

The basic code for text that I'm trying to amend is

Dim bmRange As Range

Set bmRange = ActiveDocument.Bookmarks("myBookmark").Range

bmRange.Text = "Inserted Text"

ActiveDocument.Bookmarks.Add _
Name:="myBookmark", _
Range:=bmRange

I assume that what i need to do is somehow set "bmRange.Text" to the AutoText
when i've tried this i get the name of the AutoText as text instead of the
actual AutoText. I aslo would like to use a graphic AutoText.
 
D

Dave Lett

Hi Mark,

You're almost there:

Dim bmRange As Range
Set bmRange = ActiveDocument.Bookmarks("myBookmark").Range

'''Insert AutoText
ActiveDocument.AttachedTemplate.AutoTextEntries(1).Insert Where:=bmRange,
RichText:=True

ActiveDocument.Bookmarks.Add _
Name:="myBookmark", _
Range:=bmRange


HTH,
Dave
 
G

Greg

Mark

Jay Freedman posted some help on this topic a while back. If I
understand you correctly you have a bookmark defined and you want to
insert text "in" the bookmark and redefine the bookmark. Try.

..Sub ScratchMacro()
Dim myRange As Range
With ActiveDocument
Set myRange = .Bookmarks("Test").Range
Set myRange = .AttachedTemplate.AutoTextEntries("NOTU").Insert _
(Where:=myRange, RichText:=True)
.Bookmarks.Add Name:="Test", Range:=myRange
End With
End Sub
 
M

mark

Thanks Dave.

It worked a treat.


Dave Lett said:
Hi Mark,

You're almost there:

Dim bmRange As Range
Set bmRange = ActiveDocument.Bookmarks("myBookmark").Range

'''Insert AutoText
ActiveDocument.AttachedTemplate.AutoTextEntries(1).Insert Where:=bmRange,
RichText:=True

ActiveDocument.Bookmarks.Add _
Name:="myBookmark", _
Range:=bmRange


HTH,
Dave
 

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