I need information on how to add a CommandButton to Word2000 and have it be
able to email that form back to the client with a set email address. I
would also need to lock that form also. It does not allow me to lock the
word document if I put in a CommandButton.

--
Message posted via http://www.officekb.com

RE: Command Button and Lock by Chuck

Chuck
Thu Apr 07 06:37:02 CDT 2005

One solution was proposed in a separate thread:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&mid=02029523-5d34-4f55-b1e9-aea600b521c6&sloc=en-us

Here's another way of doing it - note that with both solutions you may get a
message saying that the sub is trying to access your Outlook address book.
This is a security feature and may be unavoidable given that you're trying to
control Outlook from Word. You may just have to live with it (ie users will
have to grant the sub permission to use Outlook for however many minutes they
specify in the security warning message).

As for the problem with the command button, looks like you're going to have
to create your form as a template, store the code in a module, create a
toolbar that contains a command button pointing toward your macro.

Sub SendAttachment()

Dim objOutlook As Object
Dim objMailItem As Object
Dim strFilename As String

On Error GoTo errorhandler:

With ActiveDocument
strFilename = .Path & Application.PathSeparator & .Name
End With

Set objOutlook = CreateObject("Outlook.Application")

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
',1 means add attachment as copy of file
.Attachments.Add strFilename, 1
.Recipients.Add ("yourname@address.com")
.Subject = "Your Subject"
.Body = "This is a sample message."
End With
objMailItem.Display

Set objMailItem = Nothing
Set objOutlook = Nothing

Exit Sub

errorhandler:

MsgBox "Cancelled"

End Sub

"vbjohn via OfficeKB.com" wrote:

> I need information on how to add a CommandButton to Word2000 and have it be
> able to email that form back to the client with a set email address. I
> would also need to lock that form also. It does not allow me to lock the
> word document if I put in a CommandButton.
>
> --
> Message posted via http://www.officekb.com
>

RE: Command Button and Lock by Chuck

Chuck
Thu Apr 07 06:45:03 CDT 2005

Sorry, forgot to destroy objects in errorhandler, here's corrected code:

Sub SendAttachment()

Dim objOutlook As Object
Dim objMailItem As Object
Dim strFilename As String

On Error GoTo errorhandler:

With ActiveDocument
strFilename = .Path & Application.PathSeparator & .Name
End With

Set objOutlook = CreateObject("Outlook.Application")

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
',1 means add attachment as copy of file
.Attachments.Add strFilename, 1
.Recipients.Add ("yourname@address.com")
.Subject = "Your Subject"
.Body = "This is a sample message."
End With
objMailItem.Display

Set objMailItem = Nothing
Set objOutlook = Nothing

Exit Sub

errorhandler:

Set objMailItem = Nothing
Set objOutlook = Nothing

MsgBox "Cancelled"

End Sub


"vbjohn via OfficeKB.com" wrote:

> I need information on how to add a CommandButton to Word2000 and have it be
> able to email that form back to the client with a set email address. I
> would also need to lock that form also. It does not allow me to lock the
> word document if I put in a CommandButton.
>
> --
> Message posted via http://www.officekb.com
>