Command Button and Lock

  • Thread starter vbjohn via OfficeKB.com
  • Start date
V

vbjohn via OfficeKB.com

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.
 
C

Chuck

One solution was proposed in a separate thread:
http://www.microsoft.com/communitie...029523-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 ("(e-mail address removed)")
.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
 
C

Chuck

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 ("(e-mail address removed)")
.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top