Force Saving Document with New Name

D

Dave

I am opening a document with

Set DocB = Word.Documents.Open(DocA.Path & "\Intro.doc")

I would like the file to show as "Document1" (or whatever the next new
document would be) so that the user is forced to save it with a new
name.

Is this possible?

thanks,

dave
 
G

Gordon Bentley-Mix

Dave,

I'm sure it's possible, but it seems to me that you are trying to replicate
something that Word does natively. Why not make "Intro.doc" into a template
and then write code to create a new document from the template? Something
along the lines of:

Set DocB = Documents.Add("Intro.dot")

This works perfectly in the little test macro I created: the new document
was identified as "Document19" (which was the next sequential doc); and when
I saved it, Word forced me to enter a file name.

BTW, note that I didn't include a reference to 'Word' in my code as it's not
really necessary.
--
Cheers!
Gordon
The Kiwi Koder

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Dave

Dave,

I'm sure it's possible, but it seems to me that you are trying to replicate
something that Word does natively. Why not make "Intro.doc" into a template
and then write code to create a new document from the template? Something
along the lines of:

Set DocB = Documents.Add("Intro.dot")

This works perfectly in the little test macro I created: the new document
was identified as "Document19" (which was the next sequential doc); and when
I saved it, Word forced me to enter a file name.

BTW, note that I didn't include a reference to 'Word' in my code as it's not
really necessary.
--
Cheers!
Gordon
The Kiwi Koder

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.








- Show quoted text -

Hi Gordon,

I had tried that but I need to run a macro in Intro.doc and I haven't
been able to copy a macro from the ActiveDocument to the new one. This
way, I can have the macro already in Intro.doc and everything seems to
work that way.

Also, the documents will be distributed widely and sending along a
template would make this more complex, I think. This is something we
haven't tried before.

Thanks for the help,

dave
 
G

Gordon Bentley-Mix

Dave,

Now I'm confused. What sort of macro do you have in Intro.doc? What does it
do (in general terms) and how is it launched? If it's an AutoOpen macro, then
you should be able to convert it to an AutoNew macro and achieve the same
result. If it's something else, it should still be available in any documents
created from the template. And if it's some sort of 'global' function, then
I'd recommend developing an add-in instead. (See
http://word.mvps.org/FAQs/Customization/WhatTemplatesStore.htm for more info.)

As for distributing the documents / macros, it seems to me that distributing
a template would be just as easy as distibuting a document. Have a look at
http://word.mvps.org/faqs/macrosvba/DistributeMacros.htm for some pointers -
especially since, as you say, you haven't tried this before.

I'm sure there's a better solution here somewhere. Feel free to send me an
email if you'd rather take this offline or need more flexibility to explain
you situation than these postings can offer.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Dave

Dave,

Now I'm confused. What sort of macro do you have in Intro.doc? What does it
do (in general terms) and how is it launched? If it's an AutoOpen macro, then
you should be able to convert it to an AutoNew macro and achieve the same
result. If it's something else, it should still be available in any documents
created from the template. And if it's some sort of 'global' function, then
I'd recommend developing an add-in instead. (Seehttp://word.mvps.org/FAQs/Customization/WhatTemplatesStore.htmfor more info.)

As for distributing the documents / macros, it seems to me that distributing
a template would be just as easy as distibuting a document. Have a look athttp://word.mvps.org/faqs/macrosvba/DistributeMacros.htmfor some pointers -
especially since, as you say, you haven't tried this before.

I'm sure there's a better solution here somewhere. Feel free to send me an
email if you'd rather take this offline or need more flexibility to explain
you situation than these postings can offer.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.









- Show quoted text -

Hi Gordon.

Thanks for the reply.

I should have started at the beginning when I asked the original
question.

We have a document of about 170 pages which uses heading levels 1-4.
We want to develop a system that scans the document, pulls all of the
headings, puts a textbox in front of each, and puts them into a second
document which includes some introductory material.

The user will put a number in each textbox indicating how many times
the material under that heading should be printed, then use a
macrobutton to develop a third document which has only the material
the user wants and printed as many times as the user wants.

I'm doing a rough proof-of-concept for my manager. I showed her what I
have yesterday and she liked the idea and is going to take it to the
next level. If it gets approved, she'll get a real programmer to do
it. <g>

I'll keep tinkering in the mean time.

What I have so far pulls the headers, puts in the textboxes, opens the
Intro.doc file (which includes the macro for making the third
document) and puts the headers and textboxes after the introductory
material in Intro.doc.

Everything is working well enough for the demo except that if the user
saves the document, they will overwrite the original Intro.doc file.

This system will be distributed outside our office and used by many
different people. It seems to me that it would be difficult to get
them to put an add-in template in the correct folder, so if everything
could be included in the two files, distribution would be easier.

I read the pages you suggested but I'm a bit out of my league here and
may have missed something.

thanks again,

dave
 
G

Gordon Bentley-Mix

G'day Dave,

I may not have the full solution, but I do have an idea of where to start.

I do something similar with an AutoNew macro in some of my templates that
are designed to be "Master" templates - templates used for creating
templates. (See my earlier post 'Template for creating templates' for
details.) Basically, I want the AutoNew macro to run only if the template is
a "child" template, not the "Master".

In my process I use the value of a custom document property to determine
when the AutoNew macro should run and when it shouldn't - although in
hindsight I should probably use as document variable, as it's not as easy for
the users to change. My 'template creation' macro, which is an AutoOpen
macro, sets the value of this document property to something other than the
value used to indicate that the template is the "Master".

I think you could use something similar with your AutoOpen macro in
Intro.doc: write code that sets the value of a document variable to indicate
that the AutoOpen macro has run, and then evaluate this variable on the Save
event to force a SaveAs. Note that if you create a sub called 'FileSave' it
will intercept the standard Word File | Save and let you run the code to
force a SaveAs. This code can also do something clever like change the name
of the document using the .Name property of the wdDialogFileSaveAs dialog.
(Be aware that Intellisense won't list the .Name property, but it is there
and does work.)

The tricky bit of this process is that you will have to set the value of
your document variable back to whatever value you want to use to indicate
that the AutoOpen macro hasn't run every time you open your "Master"
Intro.doc to edit it. I'd recommend doing this first thing after opening the
doc, although how you even manage to open the doc to edit in the first place
is a mystery to me... ;-P.

I still think that using an AutoNew macro and a template is a better
approach though. I contract to an organisation that does something very
similar with providing templates to people who are off-site and don't have
access to the LAN. Inside the organisation they can just roll the templates
out to a network share and run a script to make sure everyone's Workgroup
Templates setting in Word points to this share, but obviously this isn't an
option for users outside the org. They get around this problem by using a
WISE installation package that puts the templates into the known location -
including a global template that has code in it that provides access to
document templates through a toolbar button. The users don't have to do
anything but run the installer and use standard Word functionality from
there. Maybe this is something you could run past the _real_ programmer when
the time comes...

Anyway, good luck with your project. Don't hesitate to ask if you need an
additional assistance.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Dave

G'day Dave,

I may not have the full solution, but I do have an idea of where to start.

I do something similar with an AutoNew macro in some of my templates that
are designed to be "Master" templates - templates used for creating
templates. (See my earlier post 'Template for creating templates' for
details.) Basically, I want the AutoNew macro to run only if the template is
a "child" template, not the "Master".

In my process I use the value of a custom document property to determine
when the AutoNew macro should run and when it shouldn't - although in
hindsight I should probably use as document variable, as it's not as easy for
the users to change. My 'template creation' macro, which is an AutoOpen
macro, sets the value of this document property to something other than the
value used to indicate that the template is the "Master".

I think you could use something similar with your AutoOpen macro in
Intro.doc: write code that sets the value of a document variable to indicate
that the AutoOpen macro has run, and then evaluate this variable on the Save
event toforcea SaveAs. Note that if you create a sub called 'FileSave' it
will intercept the standard Word File | Save and let you run the code toforcea SaveAs. This code can also do something clever like change the name
of the document using the .Name property of the wdDialogFileSaveAs dialog.
(Be aware that Intellisense won't list the .Name property, but it is there
and does work.)

The tricky bit of this process is that you will have to set the value of
your document variable back to whatever value you want to use to indicate
that the AutoOpen macro hasn't run every time you open your "Master"
Intro.doc to edit it. I'd recommend doing this first thing after opening the
doc, although how you even manage to open the doc to edit in the first place
is a mystery to me... ;-P.

I still think that using an AutoNew macro and a template is a better
approach though. I contract to an organisation that does something very
similar with providing templates to people who are off-site and don't have
access to the LAN. Inside the organisation they can just roll the templates
out to a network share and run a script to make sure everyone's Workgroup
Templates setting in Word points to this share, but obviously this isn't an
option for users outside the org. They get around this problem by using a
WISE installation package that puts the templates into the known location -
including a global template that has code in it that provides access to
document templates through a toolbar button. The users don't have to do
anything but run the installer and use standard Word functionality from
there. Maybe this is something you could run past the _real_ programmer when
the time comes...

Anyway, good luck with your project. Don't hesitate to ask if you need an
additional assistance.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.

















- Show quoted text -

Hi Gordon,

I'll have to work with these ideas a bit but they look like very good
possibilities.

Thanks again for all the help,

dave
 

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