How do you prompt a user to save a template before continuing?

R

robert_gt

I'm designing a template at work and I need to know how to get the person
filling it out to save the file under a different name at start-up.
thanks,
Robert
 
J

Jay Freedman

I'm designing a template at work and I need to know how to get the person
filling it out to save the file under a different name at start-up.
thanks,
Robert

If you really create it as a _template_ (*.dot file) and the user
creates a new document (*.doc file) based on the template by using the
File > New dialog, then they'll automatically be prompted to save it
-- and they can't save it with the same name as the template unless
they go to some serious trouble to do so.

If you want to pre-set the folder or filename, see
http://www.word.mvps.org/FAQs/MacrosVBA/ChangeSaveAsPath.htm and
http://word.mvps.org/faqs/macrosvba/SetDefFilename.htm.

If you create a document and think of it as a "template" in the
nontechnical sense, you're stuffed from the start...

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
R

robert_gt

Jay,
I saved the document as a .dot template and opened a new file, selecting a
template from my computer and then selecting my template from the folder, but
as soon as it opens (document2) it starts updating all of the fields by
opening dialog boxes to fill in the "ASK" and "FILLIN" fields that I have
created. I went through all of the dialog boxes and let it update the table
of contents and page numbers, but was never queried for a "saveas" file name.
Am I doing something wrong?
 
J

Jay Freedman

Obviously you've done something unexpected :) ("wrong" is such a negative
term...), but I can't say what unless you show me what you've done. Please
copy the code from your template's macro and paste it into a reply to this
thread.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
R

robert_gt

Jay,
Maybe that's the issue. My template doesn't contain macros. I simply
inserted "ASK" and "FILLIN" field codes in the cells that contain variable
information and plugged in "REF" field codes in those cells and, in the case
of "ASK" field codes, in the other cells and paragrapghs where that
information would apply.

I'm not much of a programmer. I'm a mechanical engineer trying to automate a
re-usable spec that is mostly generic and I'm trying to automate the
camera-specific portions.

I bought a few books about document automation and VBA, but they were like
reading the dictionary. A lot of definitions, but very few helpful examples
of how to actually write a program. They gave you little disjointed pieces of
the puzzle and told you what they meant, but were worthless when it came to
putting it all together into something useful. It was like trying to learn to
speak English by reading a dictionary.

I finally just tossed it all aside and started plugging away on my own,
using the imbedded and on-line help files. I've got something that works now,
but it still needs a little tweaking.

If you know of a book that actually explains how to write macros in VBA and
doesn't assume you already know how to do it, I'd like to hear about it.

Thanks,
Robert
 
J

Jay Freedman

OK, I see where you are.

Now that you have a template and you use File > New to create a document
based on that template (regardless of whether it has fields, macros, or
anything else), Word will prompt you for a filename if you (a) try to save
it by Ctrl+S or File > Save, or (b) try to close the document or the program
without saving first.

If you want to be prompted to save the document before then, you'll need a
macro in the template. The macro's name should be either Document_New() or
AutoNew(). Read http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm
for an explanation. The special name means that Word runs the macro every
time you create a new document based on that template. Inside that macro,
you tell Word to save the document; since the document doesn't have a name
yet, you'll automatically get the Save As dialog to give it a name.

Sub Document_New()
ActiveDocument.Save
End Sub

~~~~~~

On the subject of VBA books, I'm the wrong one to ask -- I don't read them,
and even if I did, my background isn't the same as yours. There are a couple
of mini-reviews at http://word.mvps.org/tutorials/BookRecommendations.htm
and some others at http://www.standards.com/OhMyWord/WordVBABooks.html. You
might get some help from the first batch of articles at
http://word.mvps.org/FAQs/MacrosVBA/index.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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