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

Re: Problems with Command Button with VBA code by Doug

Doug
Mon Jul 30 19:26:46 CDT 2007

Are you sure that the code is in the template that you are distributing to
the users and not somewhere else on your machine. Also, are they saving the
template in a trusted location?

See the article "Distributing macros to other users" at:

http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Laurie" <Laurie@discussions.microsoft.com> wrote in message
news:9B990866-CBBC-4D41-8537-0BC63B10ED86@microsoft.com...
> 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



RE: Problems with Command Button with VBA code by oldman

oldman
Mon Jul 30 19:28:01 CDT 2007

Hi,

Are you sending a Word Document with code attached? Are you sure the users
are getting the code which is stored in the document If you email the Word
Document many email servers will strip away all VBA code.

Old Man

"Laurie" wrote:

> 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

Re: Problems with Command Button with VBA code by Laurie

Laurie
Tue Jul 31 08:20:01 CDT 2007

Thank you both for your replies. I am e-mailing the templates to folks to
save to their computers. I will try asking them to access the document on the
network.

Thanks!


Re: Problems with Command Button with VBA code by quietlee2021

quietlee2021
Tue Jul 31 15:36:17 CDT 2007

Just a quick thought - you might want to make sure you are not adding the
code module to your Normal.dot document - that you are adding the code module
to the document that you are sending out.

It it's in your Normal.dot file, it'll only work for you. That was probably
the same point Old Man was also trying to make...

"Laurie" wrote:

> Thank you both for your replies. I am e-mailing the templates to folks to
> save to their computers. I will try asking them to access the document on the
> network.
>
> Thanks!
>