How to set the default suggested filename to be displayed by the Save As dialog the first time a user saves a new document
Article originally contributed by Dave Rado with updates from Ibrahim Elnazak and Greg Chapman
In a document that hasn't yet been saved, if you select File + Properties, type a Title, and click OK, the title will be displayed as the “suggested file name” in the Save As dialog the first time the document is saved.
However, due to a VBA bug, using:
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = "My title"
doesn't work (it doesn't affect the default SaveAs filename); and the FileProperties dialog isn't directly accessible via VBA.
However, the following does the trick (with thanks to Ibby who first came up with this workaround):
With
Dialogs(wdDialogFileSummaryInfo)
.Title = "My Title"
.Execute
End With
Important “gotcha”: Although this method does support long filenames, unfortunately it doesn't support delimiters such as underscore. If you set the title to My_Title, (as one does), the suggested filename will be My.doc. If you would like this behaviour to be changed, I hope you'll contact http://support.microsoft.com/contactus/ .
(You could get round this by intercepting the FileSave, FileSaveAll and FileSaveAs commands, and by writing an AutoClose macro to intercept the event of the user closing the document and being asked if they want to save changes, but that would be very kludgy indeed, whereas setting the Document Title is simplicity itself, provided you don't need it to support delimiters).
In the meantime, here's a work-around to the work-around by Greg Chapman that ... well... works around it :-)
Sub ChangeProps()
'change properties
If Documents.Count > 0 Then
Set dlgProp = Dialogs(wdDialogFileSummaryInfo)
' Establish title, subject, author, and keywords values
dlgProp.Title = MakeADocTitle("XXXX Form Options Specs.doc")
dlgProp.Subject = strTitle
dlgProp.Author = "Company Name"
dlgProp.Keywords = strKeywords
' Set the values
dlgProp.Execute
' Show the dialog for testing purposes
dlgProp.Show
End If
End Sub
Function MakeADocTitle(ByVal strTitle As String) As String
arrSplit = Split(strTitle, " ")
MakeADocTitle = arrSplit(0)
For I = 1 To UBound(arrSplit)
MakeADocTitle = MakeADocTitle & Chr(95) & arrSplit(I)
Next I
MakeADocTitle = MakeADocTitle
End Function