Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Button in Word Template

Status
Not open for further replies.

kabushnell

Technical User
Jun 4, 2003
81
US
I have created a professional letter template in Word. Depending on certain information about fifteen different paragraphs need to be added to the letter. What I was going to do was create a macro for each paragraph and then the user could run the macro to insert the correct paragraph, etc.

What I would like to do is insert a dropdown list of these macros in the template where the paragraph is going to be inserted so that all the user has to do is click on the correct one and the macro will run.

Is there anyway this can be accomplished?
 
Try this as a test first:

1. Open a document in MS Word™

2. Click 'Tools'

3. Select 'Macro'

4. Click 'Record New Macro...'

5. Type a name for your macro under 'Macro name:'

6. Click Assign macro to 'Toolbars'

7. Select 'Standard' & click 'Close' - Remember that macros only record mouse clicks!

(Note: A new floating Toolbar has appeared)

8. Click 'Table'

9. Select 'Insert'

10. Click 'Table...'

11. Make the table 3 columns & 4 rows

12. Click 'OK'

13. Click 'Stop recording' (the blue square) on the new floating Toolbar

Now you are ready to access & run your new macro:

14. Click 'Tools'

15. Select 'Macro'

16. Click 'Macros'

17. Select your macro's name

18. Click 'Run'

Hope this helps!

 
You MAY have trouble sharing the template with others if you do it that way.

Try the method used here:


Instead of "insert signature", you'll probably want "insert paragraph" or whatever.

Look down at the Sub Ozgur()
You could do this more easily by creating autotext entries. (Then record yourself inserting the autotext entry instead of recording the actual typing.) Anyway, remember that autotext entries are by default stored in normal.dot and you will need to copy them into YOUR template (and it must be a template). Use the organizer to do it.

Anne Troy
Way cool stuff:
 
If you are feeling adventurous, you might want to try the following. This sample displays all the AutoText entries in the template that start the same 4 characters in a drop-down list. The user selects the entry, and it is inserted into the document.

In your template, press Alt-F11 to go to the VBA screen, and insert a UserForm (Insert, UserForm). The user form needs the following objects:

Object Name
Combo box (or list box) cboPara
Command Button cmbOK
UserForm frmStdPara

Double-click in a blank space on your UserForm, and paste in the following code:

Private Sub cmdOK_Click()
' Insert the selected AutoText entry
Dim strPara As String

strPara = frmStdPara.cboPara.SelText

If strPara <> &quot;&quot; Then
ActiveDocument.AttachedTemplate.AutoTextEntries(strPara).Insert _
Where:=Selection.Range, RichText:=True
End If

frmStdPara.Hide
End Sub

Private Sub UserForm_Activate()
' Display all AutoText entries in this template where
' the name starts with &quot;para&quot;
Dim objAuto As AutoTextEntry

frmStdPara.cboPara.Clear

For Each objAuto In ActiveDocument.AttachedTemplate.AutoTextEntries
If Left(LCase(objAuto.Name), 4) = &quot;para&quot; Then
frmStdPara.cboPara.AddItem objAuto.Name
End If
Next objAuto
End Sub

Now you need a macro in your template with the following line of code to display the UserForm (you might want to assign this to a keystroke):

frmStdPara.Show

If you want the combo box to display the text in the AutoText rather than the name, change &quot;objAuto.Name&quot; to &quot;objAuto.Value&quot;.

[ponytails]
 
We do a lot of this sort of thing, and here's a tip we've found: users feel more confident about the generated document if they can see all of the possible text at some point (especially our lawyers). Therefore, instead of ADDING paragraphs, you might consider DELETING paragraphs. To really add a belt-and-suspenders approach, you can label each paragraph in hidden text or in a comment, to make sure you wind up with the paragraphs you intended to have.
 
I've got a similar problem. I need to do a find on a document for a specific word and then display a list of alternates (in a drop-down box?) from which the replacement can be selected (for instance find 'formal' and display 'official', 'legal' or 'standard', select one which then replaces 'formal')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top