VBA - Set Default Save As Name Without Opening Dialog

前端 未结 1 752
我寻月下人不归
我寻月下人不归 2021-01-27 05:32

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 chan

相关标签:
1条回答
  • 2021-01-27 05:50

    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
    
    0 讨论(0)
提交回复
热议问题