View Full Version : Solved: Run One Template from Another Template
clhare
02-09-2007, 09:35 AM
Hi all!
Is it possible to run one template from another template?
For example, I have 45 templates that I have to set up. Which one gets used depends on various criteria. So, I'd like to have a master template that brings up a userform with multiple options. Based on the options selected, I'd then like the macro in the master template to run the correct template from the group of 45.
I'm totally stumped on this one.:think:
fumei
02-09-2007, 09:44 AM
Have the userform list the templates.
The user selects one, clicks OK, it adds a new document attaching the selected template.
clhare
02-09-2007, 09:51 AM
Awsome! Thanks!
fumei
02-09-2007, 09:58 AM
Like this:Option Explicit
Public myPath As String
Private Sub CommandButton1_Click()
Documents.Add Template:=myPath & ComboBox1.Text
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim MyTemplate
myPath = "C:\TestTemplates\"
MyTemplate = Dir(myPath & "*.dot")
Do While MyTemplate <> ""
ComboBox1.AddItem MyTemplate
MyTemplate = Dir
Loop
ComboBox1.ListIndex = 0
End SubThe userform loads the combobox with all the .DOT files from the C:\TestTemplates folder. The commandbutton adds a new document and attaches the selected item from the combobox.
Note the myPath string variable is PUBLIC so it can be used in the two different procedures. You could also do it as a CONSTANT.
fumei
02-09-2007, 10:06 AM
If you want (and it would be a little neater) I would strip off the ".dot" for the items in the combobox. So instead of the combobox showing:
yadda.dot
ThisGuy.dot
Whatever.dot
ComboBox1.AddItem Left(MyTemplate, Len(MyTemplate) - 4)would strip off ".dot" - the last four characters.
The combobox would then display:
yadda
ThisGuy
Whatever
HOWEVER, then you would have to add the ".dot" back onto the string to attach the template to the new document. In this case I would use a CONSTANT, like this:Option Explicit
Public myPath As String
Const dot = ".dot"
Private Sub CommandButton1_Click()
Documents.Add Template:=myPath & ComboBox1.Text & dot
Unload Me
End Sub
mdmackillop
02-09-2007, 10:16 AM
With a bit more work you could add your criteria to the userform, which could restrict your combobox only to the relevant items.
fumei
02-09-2007, 10:17 AM
Then, if you have multiple folders containing different types of templates (not uncommon), you could have TWO comboboxes.
One listing the template folders, eg.
FinancialTemplates
PersonnelTemplates
PersonalTemplates
You would use the _Initialze event to load the TemplateFolder combo.
Then use the _Change event of that combobox to fill the second combobox with the templates of the selected folder. In which case, make the combobox loading a separate procedure.
fumei
02-09-2007, 10:19 AM
Hi Malcolm. What do you mean? The combobox would only add items that end with ".dot".
I am not sure what you mean by restrict it to relevant items.
mdmackillop
02-09-2007, 11:22 AM
Hi Gerry
See Post #1. Maybe only 3 or 4 of the templates need to be available for final selection.
fumei
02-09-2007, 07:15 PM
Ah, yes, of course.
Cheryl, doing so would be an exercise in straightforward logic. All very do-able. You just have to specify what the logic is. It may also be a question of organizing the templates files themselves.
As you did not specify the logic I just offered a way to get all 45. The selection criteria is flexible, and there are multiple ways you could set it up.
clhare
02-10-2007, 12:26 PM
Gerry,
Your suggestion re restricting the combo box to the relevant items really sounds like it would work well for this project. That way they only see the choices that are relevant.
Thanks for your help!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.