Creating Document with Varied Paragraphs

A

abs

I'm hopeful that I can explain this properly. We're using Word 2003 SP2.
User wants to create a document with multiple paragraphs. In front of each
paragraph would be a checkbox. They want to be able to check the paragraphs
they want and have a document created using just those checked paragraphs. I
suggested AutoText, but that is not what they want to do. Suggestions?
 
H

Helmut Weber

Hi,

unprotect the doc, like this,
to avoid an error, if it is already unprotected:
' ---------------------------------------------
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
End With
' ---------------------------------------------
Add checkboxes, in case they aren't already there,
in a rather quick and dirty way, beware:

' ------------------------------------------------
Dim oPrg As Paragraph
Dim rTmp As Range
For Each oPrg In ActiveDocument.Paragraphs
Set rTmp = oPrg.Range
rTmp.Collapse Direction:=wdCollapseStart
If Asc(oPrg.Range.Characters.First) <> 21 Then
oPrg.Range.FormFields.Add _
Range:=rTmp, _
Type:=wdFieldFormCheckBox
End If
Next
' ------------------------------------------------

Protect the doc, in case it isn't protected,
like this, to avoid an error:
' -------------------------------------------
With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect wdAllowOnlyFormFields
End If
End With
' -------------------------------------------
Get the text from the checked paragraphs, like this:

' -------------------------------------------
Dim oFld As FormField
Dim sTmp As String
For Each oFld In ActiveDocument.FormFields
If oFld.Type = wdFieldFormCheckBox Then
If oFld.Result = True Then
sTmp = oFld.Range.Paragraphs(1).Range.Text
sTmp = Right(sTmp, Len(sTmp) - 1)
MsgBox sTmp
End If
End If
Next

"like this" means there maybe other and better ways.
Lots of complications possible, e.g. tables, textframes, ...



HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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