Reputation: 555
I have an autotext entry that contains 2 plain text
content control elements. When I insert it manually it works as intended with content controls intact. Like this:
But when I try to insert it using VBA with the code like this:
NonclientRange.Text = NormalTemplate.AutoTextEntries(2)
The content controls are lost and I get just regular text like this:
If there is a way to insert it manually, surely there is a way to insert it with code too?
Upvotes: 0
Views: 690
Reputation: 7860
If you assign an AutoTextEntry
or a BuildingBlock
to the Text
property of a range all you will get is the unformatted text of the entry.
Your code also relies on the default property of the AutoTextEntry
which is its value. As Value
is a string all you will get back is the unformatted text of the entry. You should also be aware that since Word 2007 AutoText has been superceded by Building Blocks.
Whenever you are unsure of how to do something in Word first try recording a macro. The code produced won't be ideal but it should give you an idea of which object(s) to use. Your next step should be to look up the objects in the Object Browser and the online Word VBA reference. In this instance you should look up the reference for the BuildingBlock.Insert method.
Your code for inserting the entry would be something like:
NormalTemplate.BuildingBlockEntries(BuildingBlockName).Insert Where:=NonclientRange, RichText:=True
Upvotes: 1