Forms in word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a form telmpate it word and locked is so that you can only edit the
fields. Is there any way to allow users to copy the entire document so they
can paste it into outlook message?
 
The following macro will unlock the form, convert the form content to text
then mail the form to an address of your choice using Outlook.

Sub MailTheForm()
Dim i As Integer
Dim bProtected As Boolean
Dim bStarted As Boolean
Dim sForm As String
Dim sAddr As String
Dim sSubject As String
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

sAddr = "(e-mail address removed)" 'Put the return address here
sSubject = "Message subject" 'Put the subject here
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
With Selection
.WholeStory
.Fields.Unlink
sForm = Selection
.HomeKey Unit:=wdStory
End With

On Error Resume Next

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 = sAddr
.Subject = sSubject
.Body = sForm
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing
MsgBox "The form has been sent to your Outlook outbox", vbInformation
ActiveDocument.Save
End Sub


http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
next qestion, is there a way to have the user define the recipients of the
e-mail without having them edit VB?
 
Better yet, how would I send it to outlook draft folder and then edit who i
send it to from there?
 
It is easy enough to add the means to insert the recipient's e-mail address
from Outlook with the marked section.

Sub MailTheForm()
Dim i As Integer
Dim bProtected As Boolean
Dim bStarted As Boolean
Dim sForm As String
Dim sAddr As String
Dim sSubject As String
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem


'*****************************************************
sAddr = InputBox("Enter recipients e-mail address")
If sAddr = "" Then
MsgBox "User cancelled or no name listed", , "Cancel"
Exit Sub'
End If

'*****************************************************
sSubject = "Message subject" 'Put the subject here
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
With Selection
.WholeStory
.Fields.Unlink
sForm = Selection
.HomeKey Unit:=wdStory
End With

On Error Resume Next

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 = sAddr
.Subject = sSubject
.Body = sForm
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing
MsgBox "The form has been sent to your Outlook outbox", vbInformation
ActiveDocument.Save
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Back
Top