ironman05
asked on
Create a submit button in Word that will save the file and send an email
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"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Appl ication")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olM ailItem)
With oItem
.To = "emailaddress@email.com"
.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.Ful lName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
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!
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.Appl
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olM
With oItem
.To = "emailaddress@email.com"
.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.Ful
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the info
ASKER