Change default filename in SaveAs Dialog

风流意气都作罢 提交于 2019-12-08 06:17:35

问题


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:


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.



来源:https://stackoverflow.com/questions/49059857/change-default-filename-in-saveas-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!