我有一个脚本通过电子邮件将完整的表单发送给我,但是一旦用户点击提交按钮,我就需要它来关闭表单。
以下是我为电子邮件部分编写的脚本,但是一旦提交,我该如何更改以使其关闭?
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
答案 0 :(得分:0)
要关闭当前文档,可以在代码末尾插入:
Application.ActiveDocument.Close
要确保关闭所有Word窗口,可以使用
Application.Quit
但请注意,这将关闭其他非相关文档,并且(取决于您的其他代码和设置)可能不会提示用户保存更改。