On my system, in the templates folder, I have a template with the name of
FormsizerDemo.dotm that contains a module with the name of ModWords and in
that module is Sub RunWords that contains the commands to display a userform
that is in the FormsizerDemo.dotm
Then, in a template that is saved in the Word Startup Folder, I have the
following macro:
Sub FormSizer()
ActiveDocument.AttachedTemplate =
"C:\Users\Doug\AppData\Roaming\Microsoft\Templates\FormsizerDemo.dotm"
Application.Run "ModWords.RunWords"
End Sub
Now, if I create a new blank document (from the Normal template) and then
run the macro FormSizer (which is available because the template in which it
is located is in the Startup folder, it attaches the FormSizerDemo template
to the blank document and displays the userform that is called by the
RunWords macro in the FormsizerDemo.dotm template.
If I was wanting to do this all of the time, I would put a button to run the
FormSizer macro on the Ribbon (in Word 2007) or on a toolbar in earlier
versions.
In your case, the Sales.dot would take the place of FormsizerDemo.dotm in
the above example and in the template that is stored in the startup folder,
you would have a macro that attached that template to the document that was
active when it was run using
ActiveDocument.AttachedTemplate = "[path]\sales.dot"
Application.Run "[modulename].[macroname]"
to display the userform that is in sales.dot where the modulename is the
name of the module in sales.dot that contains the macro ([macroname]) that
causes the userform to be displayed.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Ralf said:
Hello Doug,
After some trial and error, I think I'm lost.
I'm trying to get to work the userform in an empty new document first of
all
and then take it to step two, where you say I'm best off just making a
macro
in a template.
I have a couple of questions/problems:
- Can I place
Sub Autonew()
ActiveDocument.AttachedTemplate = "[path]\Sales.dot"
End Sub
in ThisDocument of a random new document created from normal.dot to call
upon the template and be able to have the userform pop up?
- Do I then still need to call upon the sales.dot template in the Add-ins
in
Word?
- Do I still have to put a Private Sub Document_New() in ThisDocument of
the
sales.dot template? Or does this have the same function as the script you
posted previously?
- When I activate sales.dot in the empty new document and go into the
visual
basic project the template is locked even though it's not password
protected
or write protected.
- How do you go about making a macro button in Word to call upon the
template in a new document?
Thank you in advance.
Ralf
Doug Robbins - Word MVP said:
If you were to put
Sub Autonew()
ActiveDocument.AttachedTemplate = "[path]\Sales.dot"
End Sub
in the normal.dot template, it would attach the Sales.dot template to all
documents created from the Normal.dot template.
In addition, if the CRM software is any good, it may well include a
command
that prevents auto macros from running so that they do not interfere with
what it wants to be done. Plus, screwing around with a user's normal.dot
template is like fiddling around with their underwear.
What I would do is create a macro containing the
ActiveDocument.AttachedTemplate command in a template that was
distributed
to users and saved into their Word Startup folder and have toolbar in
that
template that contained a button to run the code. Then when the user
creates a document via the CRM, they could click on that button to attach
the template. You could also then include in the code the commands to
call
the userform.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Hello Doug,
Thanks for this. Should it put this in my normal.dot? Because the new
documents that are generated are all empty and therefore originating
from
my
normal.dot.
Can you give any tips as to how I would do this with multiple people
working
on the same documents? Should I replace the normal.dot on every
instance
of
MS Word in the office that needs to use the document?
Ty so much.
Greetings,
Ralf
:
If you use the following code to attach your template to the document
that
has been created, the macros in Sales.dot will be available for use
with
that document.
ActiveDocument.AttachedTemplate = "[path]\Sales.dot"
replace [path] with the appropriate Drive:\Path
--
Hope this helps,
Doug Robbins - Word MVP
Please reply only to the newsgroups unless you wish to obtain my
services
on
a paid professional basis.
Hello Doug,
Thanks for the response. Our CRM software creates a WORD document
with
a
referencenumber that is then stored on the server so it can be
called
upon
from the CRM software. In other words, we need to work with the
document
that
the CRM software initializes. The only way that I know of to use a
template
with it, is to insert > file the .dot template.
If I make a new document with the template, it won't have the
reference
number. And it can't be renamed because the document with that
number
already
exists. (so the CRM software would never be able to call upon the
document
because it only stores the documents with the right reference
numbers
under
the projects of customers. (the software is Navision)
:
Why aren't you creating the documents by selecting New from the
File
menu
and then selecting the Sales.dot template as the basis for the
document
that
you want to create?
--
Hope this helps,
Doug Robbins - Word MVP
Please reply only to the newsgroups unless you wish to obtain my
services
on
a paid professional basis.
Hi guys,
Let me sketch the situation for you:
What I have:
- a 'sales.dot' template with auto text fields and a userform
which
inserts
pieces of text in the template when certain options are clicked
on
the
userform
What I need:
- since I use a piece of CRM software that, when a new offer has
to
be
made,
makes an empty .doc file (from normal.dot I presume) I import the
above
.dot
template as a file (import > file) to have Word import certain
data
from
the
database connected to the CRM software to auto merge fields.
Although
this
gives the document the proper look, it doesn't import the
userform
I've
made
in that specific .dot template. When I import the sales.dot file
into
the
.doc, I need it to also import the userform and VBA attached to
the
.dot
What I know:
I've read about at least using the sales.dot file I made into the
add-ins
in
Word so it loads on startup. Other than that, I've read that I
need
to
call
upon the userform in normal.dot to actually make it work with any
templates I
import as a file.
Is there another way about this, or do I need to write an
additional
script
for the normal.dot file to make this work? Also to keep in mind
is
that
I'm
not the only one who will be using the document, so that might
mean
normal.dot has to be adapted on the PCs of all users or through
storing
a
.dot on a network location.
I hope you can help!
Sincerely,
Ralf