Can I set the value that MS word will use in the 'Save' dialog ?

Usually when a word document is saved, Word will select the first few words of the document in an attempt to auto-create a document name. But I have a textbox near the top of the document that will contain the customers name, and then the user exits the field I want to be able to set the value that word will use to save the document.

Any help is appreciated.

Dani AI

Generated

A practical way to have Word suggest the customer name (from the top textbox) as the default file name is to copy that value into the document’s Title field via the File Summary dialog object — Word uses that Title as the suggested Save As name for a new, unsaved document. Hook this into the document-level content-control exit event so the Title is updated as soon as the user leaves the customer field. Put the code in the ThisDocument module so the event fires for the active document.

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    If CC.Title = "CustomerName" Then
        Dim s As String
        s = Trim(CC.Range.Text)
        If Len(s) = 0 Then Exit Sub

        ' sanitize characters that Word may treat specially
        s = Replace(s, "_", " ")
        s = Replace(s, "-", " ")
        s = Replace(s, ".", "")

        With Dialogs(wdDialogFileSummaryInfo)
            .Title = s
            .Execute   ' applies the summary info without showing the dialog box
        End With
    End If
End Sub

This uses the ContentControlOnExit event (so choose a content control for the customer textbox and set its Title to "CustomerName") and sets the File Summary Title programmatically; Word then pre-populates the Save As filename with that Title the first time the document is saved. The direct approach of assigning BuiltInDocumentProperties(wdPropertyTitle) does not reliably change the Save‑As suggestion, which is why the FileSummaryInfo dialog workaround is used. (learn.microsoft.com)

Caveats and tips: sanitize or truncate the name (underscores, hyphens and some punctuation can cause truncation or unexpected results), test on the target Word versions and with the UI path users will use (Ctrl+S vs File→Save behave inconsistently for prepopulation in some environments). If the goal is to force a specific filename rather than just suggest it, calling SaveAs programmatically (as hinted) is an alternative. For background on the dialog properties and Execute vs Show behavior, see the Microsoft docs and the WordMVP workaround note. (learn.microsoft.com)

Recommended Answers

All 3 Replies

If I've read your post correctly I think your talking about changing the file name from something other than what Word suggest. I mean if you have a document with the single sentence "Hi there" in it, Word will use that as the filename, but you should be able to simply erase it and write a new name before saving.

If I've read your post correctly I think your talking about changing the file name from something other than what Word suggest. I mean if you have a document with the single sentence "Hi there" in it, Word will use that as the filename, but you should be able to simply erase it and write a new name before saving.

Yes, but I would like to do this programmatically. In theory word holds the name of the document somewhere and you should be able to get at it through VBA. If I let the user fill out the form and save it and suggest a name, you could get anything.

will this one help

Sub save_as()
Dim str As String

str = InputBox("Pls. enter filename to be saved")

 ActiveDocument.SaveAs FileName:=str & ".doc", FileFormat:=wdFormatDocument
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.