Changing suggested filename when saving doc for first time

J

Jen

Hello,

Is there any rhyme or reason to how Word suggests the
filename for a new doc when you save it for the first
time?

I am working on a template for someone where he would like
to have the filename built from some input the users enter
into a dialog box.

The document has a macro with the dialog box (which also
populates places in the doc) and have been able to create
the string desired for the suggested filename and insert
it into the doc Properties, Title area, but I have not
been able to get Word to consistently draw from this field
to suggest the filename when saving.

Sometimes it will draw from this field, but more often it
ends up taking the first line of the doc. I tried
deleting the title property in the template itself so it
could be inserted cleanly by the macro (and not replace
anything). I also tried adding a bit to my macro that
inserts the desired string into the first line of the doc
(with a style of a very small and white font size so it
doesn't show up on the actual doc). It still wants to
take the following line as the filename. I also tried
changing the style of the following line (which I don't
want as the suggested filename but is the title of the
document) so "title" was not in its stylename, and
changing the style of the first line to include "title" in
its stylename.

The template is a form and has a protected section with
checkboxes. Could the protection be interfering in any
way?

Where does the document property of title on the contents
tab come from? I see that it is set to what the suggested
filename often comes up as, but I cannot figure out how to
change it and can't find anything about it in Word help.

Thanks in advance for any help anyone can provide!
jen
 
G

Greg Maxey

Jen,

You could interupt the built in Word FileSaveAs command
with a macro that saves the with a name from your dialog
box. Here is a example I adapted from an earlier posting
by Doug Robbins that will save the file using an input
from a formfield bookmarked FileName.

Sub FileSaveAs()
Dim mydoc As Document
Set mydoc = ActiveDocument
mydoc.SaveAs mydoc.FormFields("FileName").Result & ".doc"

End Sub
 
J

Jen

Hi Greg,

This works, but it saves the doc automatically to the
default directory and I want the user to be able to put
the doc anywhere they want, ideally through the regular
Save As dialog box... I only want to insert the filename.

Why does Word make it so difficult to do such a seemingly
simple thing?

Thanks for the tip, it will be helpful for me in the
future. Do you have any other suggestions about getting
the dialog box to show AND setting the filename?
jen
 
G

Greg Maxey

Jen,

I am a novice with VBA and not much help. You say you
have the file name available as a string. I declared
FileName as a String and then used the document property
title as the string value. Try:

Sub FileSaveAs()

Dim FileName As String
FileName = ActiveDocument.BuiltInDocumentProperties
(wdPropertyTitle)
Set UserSaveDialog = Dialogs(wdDialogFileSaveAs)
UserSaveDialog.Name = FileName
UserSaveDialog.Display
End Sub

Note the (wdPropertyTitle) should be on the same line with
FileName = ..

HTH
 
J

Jen

Greg,

This is exactly what I was looking for! The last two
lines (to get the dialog box to display and set the
filename) were just what I was missing. Works perfectly.
Thanks so much for your help.

Best
jen
 

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