我创建了一个包含表单字段的2010 Word文档和一个用于通过电子邮件发送表单的命令按钮。我确实找到了在发送电子邮件后关闭文档的代码但是,我需要它在关闭文档之前不保存更改或清除字段并在关闭之前取消选中复选框。
目标是每次都打开一个新的形式。
他们也是一家合同公司,所以我发送表格给他们保存到他们自己的驱动器,其他明智的我会保存到我们的模板。
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 = "Medical/Psych router"
.To = "test@email.com"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Application.ActiveDocument.Close
End Sub
答案 0 :(得分:0)
尝试将其保存到临时文件夹 C:\Temp\
,主文档将为空白,您将在文件 C\Temp\
中保存新文件名为Medical_Psych_router今天的日期是Jun_18_2015。的 (Medical_Psych_router Jun_18_2015)
强>
Option Explicit
Private Sub CommandButton1_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim sFileName As String
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
sFileName = "Medical_Psych_router " & Format(Now, "mmm_dd_yyyy")
Doc.SaveAs FileName:=("C:\Temp\") & sFileName, _
FileFormat:=wdFormatDocument, _
AddToRecentFiles:=True
'Doc.Save
With EmailItem
.Subject = "Medical/Psych router"
.To = "test@email.com"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Application.ActiveDocument.Close SaveChanges:=False
End Sub