Change default filename in SaveAs Dialog

2019-06-01 05:24发布

I am trying to change the proposed filename within the "Save As"-Dialog based on the content of a Content Control.

My understanding was that Word is proposing the Document Property „Title“ within the SaveAs Dialog.

Within an empty Document I created a Content Control (Text only) and put the following code in "This Document".

Private Sub Document_ContentControlOnExit(ByVal objCC As ContentControl, _
        Cancel As Boolean)
    ActiveDocument.BuiltInDocumentProperties("Title") = objCC.Range.Text
End Sub

The built-in Property "Title" changed on leave as expected but pressing the Save As Button did not change the proposed filename.
Cancelling the "SaveAs"-Dialog and opening it once again (without any other actions in between) the "new" Title was proposed as default filename.

Process:
1. Change Title to „New Filename“
2. Press Save As -> Proposed Filename „Doc1“
3. Cancel Save As
4. Press Save As -> Proposed Filename „New Filename“
5. Change Title to „Better Filename“
6. Press Save As -> Proposed Filename „New Filename“
7. Cancel Save As
8. Press Save As -> Proposed Filename „Better Filename“

...

Is there a Workaround to this "Feature" or am I just wrong?

1条回答
Deceive 欺骗
2楼-- · 2019-06-01 05:55

I may have misunderstood

Sub test()

Dim objCC As ContentControl

Set objCC = ActiveDocument.ContentControls.Add(wdContentControlText)

objCC.Range.Text = "Asparagus"

End Sub

Private Sub Document_ContentControlOnExit(ByVal objCC As ContentControl, Cancel As Boolean)
    MsgBox ActiveDocument.BuiltInDocumentProperties("Title")
End Sub

This yields "Asparagus"

And that is also the proposed FileName on save.

查看更多
登录 后发表回答