0

我有一个脚本可以通过电子邮件将完成的表单发送给我,但是一旦用户单击提交按钮,我需要它来关闭表单。

这是我为电子邮件部分准备的脚本,但是一旦提交,我该如何更改以使其关闭?

Private Sub CommandButton1_Click()
Dim OL              As Object
Dim EmailItem       As Object
Dim Doc             As Document

Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save

With EmailItem
    .Subject = "Privacy Information Questionaire"
    .Body = "Privacy Information Questionaire" & vbCrLf & _
    "Body Line 2" & vbCrLf & _
    "Body Line 3"
    .To = "email@example.com"
    .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
    .Attachments.Add Doc.FullName
    .Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub
4

1 回答 1

0

要关闭当前文档,您可以在代码末尾插入:

Application.ActiveDocument.Close

为确保所有 Word 窗口都已关闭,您可以使用

Application.Quit

但是请注意,这将关闭其他不相关的文档,并且(取决于您的其他代码和设置)可能不会提示用户保存更改。

于 2013-09-26T18:01:43.257 回答