VBA - 在不打开对话框的情况下设置默认另存为名称 [英] VBA - Set Default Save As Name Without Opening Dialog

查看:87
本文介绍了VBA - 在不打开对话框的情况下设置默认另存为名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Access 中使用 VBA 创建了一个 Word 文档,方法是创建一个新的 Word.Application,使用 Documents.Add 导入一个文档,然后进行所需的更改.更改完成后,文档即被激活,Word 将获得焦点.

我正在尝试更改用户第一次尝试单击另存为"时显示的建议名称.在本文档中,但没有立即打开对话框.

我已经使用

设置了一个标题

.ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = 标题"

一旦文档被激活,但我遇到了一些奇怪的行为.

我第一次点击另存为"时在文档上,会出现一个基于文档内容的自动建议名称.但是,当我关闭此对话框并单击另存为"时,第二次出现正确的名字.

其他用户似乎遇到了这个问题此处.>

是否有针对此行为的解释/修复,如果没有,是否有我可以使用的替代方法?

非常感谢您的帮助.

解决方案

这是我几年前想到的.它还设置 .BuiltInDocumentProperties(wdPropertyTitle).

是使用,而不是显示,oWord.对话框(wdDialogFileSummaryInfo).

' 窗口标题sWindowTitle = 文档"&姓名' http://wordmvp.com/FAQs/MacrosVBA/SetDefFilename.htm使用 oWord.Dialogs(wdDialogFileSummaryInfo)' 多个字符会导致 Word 在保存时截断默认文件名sClean = sWindowTitlesClean = Replace(sClean , ".", "") ' 约翰·史密斯博士sClean = Replace(sClean, "-", " ") ' Anne-Marie Jones' ...根据需要扩展....Title = sClean.执行结束于使用 oDoc.ActiveWindow.Caption = sWindowTitle结束于

I have created a Word document using VBA in Access by creating a new Word.Application, importing a document with Documents.Add and then making the desired changes. Once the changes are made the document is activated and Word is given focus.

I'm trying to change the suggested name that appears when a user first tries to click "Save As" in this document, but without opening the dialog immediately.

I have set a title using

.ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = "Title"

once the document has been activated, but am experiencing some strange behaviour.

The first time I click "Save As" on the document, an automatically suggested name based on the contents of the document appears. However, when I close this dialog and click "Save As" for a second time, the correct name appears.

It appears that another user has experienced this issue here.

Is there an explanation/fix for this behaviour, and if not is there an alternative approach I could use?

And help would be much appreciated.

解决方案

This is what I came up with some years ago. It also sets .BuiltInDocumentProperties(wdPropertyTitle).

The key is to use, but not show, oWord.Dialogs(wdDialogFileSummaryInfo).

' Window title
sWindowTitle = "Document for " & sName

' http://wordmvp.com/FAQs/MacrosVBA/SetDefFilename.htm
With oWord.Dialogs(wdDialogFileSummaryInfo)
    ' Several characters will cause Word to truncate the default file name when saving
    sClean = sWindowTitle
    sClean = Replace(sClean , ".", "")   ' Dr. John Smith 
    sClean = Replace(sClean , "-", " ")  ' Anne-Marie Jones
    ' ... expand as needed ...

    .Title = sClean 
    .Execute
End With

With oDoc        
    .ActiveWindow.Caption = sWindowTitle
End With

这篇关于VBA - 在不打开对话框的情况下设置默认另存为名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆