Create a submit button in Word that will save the file and send an email
Posted on 2010-01-04
I have the current code that does the email part just fine:
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"
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
Set oItem = oOutlookApp.CreateItem(olMailItem)
.To = "firstname.lastname@example.org"
.Subject = "Survey"
'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"
If bStarted Then
Set oItem = Nothing
Set oOutlookApp = Nothing
However, I would like the submit button to save first and then email. I don't want to have to click save or do any short key. I would like for a user to just fill out the form and click one button (the submit button) and it will do everything else (save and email).
I would like to modify the code above to add the save portion. Thank you in advance!