L
Laurie
Hello,
I created a form in Word. It is saved as a read-only template and it's
protected so that users can only change the form fields.
There is a command button called "E-Mail Document" that users can click and
the document is e-mailed to a specific address. The form is meant to be used
over and over again.
I've tested the form repeatedly and the control button always works.
However, my users are reporting that it is not working. When I go into the
forms they are sending back, the VBA code is gone. How is this happening??
My code is below.
Thank you!
---------------------------------------------------------------------------------------------
Private Sub EMailDocument_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 = "REDACTED"
.Subject = "Site Visit Document"
'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
I created a form in Word. It is saved as a read-only template and it's
protected so that users can only change the form fields.
There is a command button called "E-Mail Document" that users can click and
the document is e-mailed to a specific address. The form is meant to be used
over and over again.
I've tested the form repeatedly and the control button always works.
However, my users are reporting that it is not working. When I go into the
forms they are sending back, the VBA code is gone. How is this happening??
My code is below.
Thank you!
---------------------------------------------------------------------------------------------
Private Sub EMailDocument_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 = "REDACTED"
.Subject = "Site Visit Document"
'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