我有一個鎖定的Word形式,只提供,用戶可以填寫字段當他們到達終點,有一個提交按鈕,這是用下面的代碼的Active X控件:如何在提交Word表單後添加成功消息? 。
Private Sub CommandButton1_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "email address"
.Subject = "New subject"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
我將Outlook庫添加到引用中,因此,當我單擊該按鈕時,它會按照預期以Word文檔作爲附件發送電子郵件。問題是沒有告訴用戶它已經工作的消息。我擔心用戶只會一遍又一遍地按下按鈕發送多封電子郵件。我通常不會做VBA,但是對於我目前的任務來說這是必要的,所以任何幫助都將值得讚賞。
'MsgBox'你的消息是如何發送的? – xidgel