Putting an autotext entry into a user form textbox

S

Steve L

This is actually a two part question.
I have a user form that populates a list box with all of the names of
autotext enteries. The user can select a name from the list and then insert
the entry into the document. I would like to be able to have a textbox
beside the list box that will show the currently selected autotext entry as a
preview before it is inserted. I have gotten the entry name to be inserted
in the textbox, but not the entry itself. I have tried several variations of
the same code that inserts the entry into the document as the text value for
the textbox, but I have not been successful.

1. Is there a way to have the autotext entery inserted into a form textbox
for viewing before it is inserted into the document

2. Is there a way to capture which entry is currently selected and display
the selection without using a command button. I currently have two command
buttons "View" and "Insert"

Below is the code I am using:
Populate list box and insert into document;

Dim auto_entry_names As String
Dim selected_name As String
Dim myTemplate As Template
Dim stuff As AutoTextEntry

'Set the template name which is the attached template (BUMC_PPTemplate)
Set myTemplate = ActiveDocument.AttachedTemplate

'First we'll populate the items for "lstBox"
'load the Tumor Template names from the autotext directory in lstBox
lstBox.Clear

For Each Entry In myTemplate.AutoTextEntries
auto_entry_names = Entry.name
lstBox.AddItem auto_entry_names
Next

'Set the first row to be selected by default
lstBox.ListIndex = 0

Exit Sub

'File Error Section
FileError:
MsgBox "An unexpected error has occured"
End Sub

Private Sub b_cancel_Click()

Unload Me
End Sub


Private Sub b_OK_Click()

selected_name = lstBox.Value
WordBasic.Insert selected_name
WordBasic.InsertAutoText

Unload Me

End Sub
 

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