Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Creating Document with Varied Paragraphs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abs - 18 Oct 2006 21:31 GMT
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?
Helmut Weber - 19 Oct 2006 03:15 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.