- Joined
- Oct 12, 2015
- Messages
- 1
- Reaction score
- 0
Hi,
Am have created a Form in word, that has a Command button that opens up a msgbox, this message box ask a question for a yes/ no answer,
I am unable to get it to return to document when no is selected, when Yes is selected it is to email form to specified email, the macro coding I am using is:
Private Sub CommandButton1_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim Response
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
Response = MsgBox("have you acknowledged privacy?", vbYesNo + vbQuestion)
If Response = vbYes Then
With EmailItem
.Subject = "Data Request"
.Body = "Data request form attached"
.To = "(e-mail address removed)"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.SEND
End With
Else
Doc.ReturnToLastReadPosition
End If
Application.ScreenUpdating = True
Set Doc = Nothing
OL.Quit
Set OL = Nothing
Set EmailItem = Nothing
End Sub
I had this work once, and now cannot get to work at all,
now if it does anything, it is trying to send email when either yes or no is selected.
Further to this, when I have Outlook open, when no is selected it closes down outlook
Am have created a Form in word, that has a Command button that opens up a msgbox, this message box ask a question for a yes/ no answer,
I am unable to get it to return to document when no is selected, when Yes is selected it is to email form to specified email, the macro coding I am using is:
Private Sub CommandButton1_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim Response
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
Response = MsgBox("have you acknowledged privacy?", vbYesNo + vbQuestion)
If Response = vbYes Then
With EmailItem
.Subject = "Data Request"
.Body = "Data request form attached"
.To = "(e-mail address removed)"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.SEND
End With
Else
Doc.ReturnToLastReadPosition
End If
Application.ScreenUpdating = True
Set Doc = Nothing
OL.Quit
Set OL = Nothing
Set EmailItem = Nothing
End Sub
I had this work once, and now cannot get to work at all,
now if it does anything, it is trying to send email when either yes or no is selected.
Further to this, when I have Outlook open, when no is selected it closes down outlook
Last edited: