“另存为”对话框中的“保存”和“取消”按钮

Save and Cancel buttons in Save As dialog box

我正在创建一个宏来:

  1. 请求 "work order" 编号和要处理的文件(确定)
  2. 在新文档中插入工单编号和文件文本(确定)
  3. 如果单击“取消”按钮 (KO),将新创建的文件保存在新位置并撤消所做的更改

我的问题是当我点击 "Save" 按钮时,没有任何反应。对话框消失但文件未保存,字段未更新且表单未卸载(最后几行)。我该如何处理这些按钮?

这是我目前所做的:

Private Sub btn_generate_Click()
    Dim dlgSave As FileDialog
    Set dlgSave = Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)
    Dim oRegex As New regexp
    oRegex.Pattern = "^[0-9]+$"

'Check if WO is only digits
If (oRegex.Test(txt_wo) = False) Xor (txt_wo.TextLength <> 6) Then
    'Alert message
    MsgBox "The WO must be 6 digits!", vbExclamation, "Error in WO number"
    'Focus on the WO textbox + selection of the content
    txt_wo.SetFocus
    txt_wo.SelStart = 0
    txt_wo.SelLength = Len(txt_wo.Text)

'Check if path to file is filled
ElseIf txt_filePath.Text = "" Then
    'Alert message
    MsgBox "You must choose a document to reference", vbExclamation, "Missing document"
    'Focus on the "Browse"button
    btn_browse.SetFocus
Else

'Put WO after the bookmark "workorder"
ActiveDocument.Bookmarks("workorder").Range.InsertAfter (" " + txt_wo.Text)

'Copy text of the chosen file after the bookmark "texttoref"
ActiveDocument.Bookmarks("texttoref").Range.Select
Selection.InsertFile (txt_filePath)

'Open "Save as..." dialog box
With dlgSave
    .InitialFileName = "eRef" + txt_wo.Text + ".docx"

    'If the user clicks "Save"
    If .Show = False Then
        ActiveDocument.Undo 2
    End If
End With

Unload Form_CreateSheet
ActiveDocument.Sections(1).Headers(1).Range.Fields.Update
End If
End Sub 

如果有人可能感兴趣。这是有效的修改部分

     With dlgSave
    'Set default name of document
    .InitialFileName = "DefaultName.docx"

    If .Show = False Then
        'undo the insertions
        ActiveDocument.Undo 2
    Else
        ActiveDocument.SaveAs (.InitialFileName)
    End If