Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Display SaveAs Dialog with suggested filename using underscores

1,694 views
Skip to first unread message

Sally Green

unread,
Oct 21, 2009, 2:04:07 AM10/21/09
to
Using vba code and Word 2003, I need to be able to suggest a file name in the
Save As dialog using underscores to separate words, eg My_filename.doc

I have tried all manner of things to do this and have partially succeeded
using:
ActiveDocument.SaveAs "My_filename"

However, I need the Save As dialog to show so that the user can select the
relevant folder. As this folder can change from user to user I can't default
the path into the code. I need a NoPrompt argument like the Save Method.
I've also used:
ActiveDocument.BuiltInProperties(wdPropertyTitle)="My_filename" but that
then suggest My.doc as the filename, everything after the underscore is
dropped out.
I've also tried the WordBasic.SetDocumentProperty "Title",0, "My_Filename"
- same problem.
And Documents.Save NoPrompt:=False with the same frustrating result.

I found a useful article in
http://word.mvps.org/faqs/macrosvba/SetDefFilenameContent.htm

The work around worked really well, it placed my very long filename with
appropriately placed underscores into the Title Property and the .show on the
wdDialogFileSummaryInfo showed the title. However, when my code gets to the:

Dialogs(wdDialogFileSaveAs).Show

the Save As dialog box is displayed but the suggested filename does not pick
up the full name from the Document Properties - Title. Everything after the
underscore is dropped out.

Is there a known fix for this.

My request in brief is to be able to display the Save As dialog with a
suggested name that includes underscores.

Any help on this would be appreciated.

Thanks
SG


I posted this once, but it hasn't appeared in the posted list. Apologies if
it appears twice.

Doug Robbins - Word MVP

unread,
Oct 21, 2009, 3:32:40 AM10/21/09
to
Use:

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogSaveAs)
With fd
.InitialFileName = "FirstName_LastName"
If .Show = CANCEL_PRESSED Then
Else
.Execute
End If
End With
Set fd = Nothing


--
Hope this helps

Doug Robbins - Word MVP
Please reply only to the newsgroups unless you wish to avail yourself of my
services on a paid, professional basis.

"Sally Green" <Sally...@discussions.microsoft.com> wrote in message
news:0D18D75C-EE36-4E61...@microsoft.com...

R. Odden@discussions.microsoft.com Jon R. Odden

unread,
Feb 16, 2010, 4:50:05 PM2/16/10
to
What is the CANCEL_PRESSED?

I try this in Office 2007 and get a Compile error: Variable not defined. And
of course - this is correct. So how can this work?


Regards,
Jon

> .
>

Doug Robbins - Word MVP

unread,
Feb 16, 2010, 5:51:09 PM2/16/10
to
It does not produce an error here. However you can also use:

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogSaveAs)
With fd
.InitialFileName = "FirstName_LastName"

If .Show = 0 Then 'user pressed the cancel button


Else
.Execute
End If
End With
Set fd = Nothing

End Sub


--
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.

"Jon R. Odden" <Jon R. Od...@discussions.microsoft.com> wrote in message
news:90DB4DA4-0123-415F...@microsoft.com...

0 new messages