View Single Post
 
Old 01-17-2020, 09:07 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Andrew, Graham


I'm Johnny come late here, but it seems a ten pound hammer is being used to drive a 6 penny nail. Not saying the discussion about control order is correct or not complicated.

First of all for the user. Using bookmarks for this purpose in the 21st century is like using a horsewhip to accelerate a Ferrari and based on your description, paragraphs (even if they are just one sentence paragraphs) seems to be a better term for what you are dealing with. Assuming that each line in your example is a paragraph I would suggest one of two methods both utilizing a richtext content controls in the document.

The both are adaptations of what you have already seen here. For the first, insert a richtext content control in your document and title it "Content" In your userform insert 9 checkboxes named Checkbox1 through Checkbox9. With a commandbutton1, run this code:



Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim Sentence(8) As Variant
Dim oCtrl As Control
Dim strText As String
Dim lngIndex As Long
  Sentence(0) = "This is the first sentence."
  Sentence(1) = "This is the second sentence."
  Sentence(2) = "This is the third sentence."
  Sentence(3) = "This is the fourth sentence."
  Sentence(4) = "This is the fifth sentence."
  Sentence(5) = "This is the sixth sentence."
  Sentence(6) = "This is the seventh sentence."
  Sentence(7) = "This is the eighth sentence."
  Sentence(8) = "This is the ninth sentence."
  For lngIndex = 1 To 9
    Set oCtrl = Controls("Checkbox" & lngIndex)
    If oCtrl Then
      If strText = vbNullString Then
        strText = Sentence(lngIndex - 1)
      Else
        strText = strText & vbCr & Sentence(lngIndex - 1)
      End If
    End If
  Next lngIndex
  ActiveDocument.SelectContentControlsByTitle("Content").Item(1).Range.Text = strText
  Hide
lbl_Exit:
  Exit Sub
End Sub
For the second, insert a richtext contentcontrol in your document titled "Content Definded". Type in your nine statements (paragraphs). Select all of the content (except the last paragraph mark) and create a buildingblock named "Content" Add a commandbutton2 to your form and Run this code:



Code:
Content"Private Sub CommandButton2_Click()
Dim oCC As ContentControl
Dim Sentence() As String
Dim lngIndex As Long
Dim oCtrl As Object
Dim strText As String
Dim oTmp As Template
  Set oCC = ActiveDocument.SelectContentControlsByTitle("Content Defined").Item(1)
  Set oTmp = ThisDocument.AttachedTemplate
  oTmp.BuildingBlockEntries("Content").Insert oCC.Range, True
  Sentence = Split(oCC.Range.Text, Chr(13))
  For lngIndex = 1 To 9
    Set oCtrl = Controls("Checkbox" & lngIndex)
    If oCtrl Then
      If strText = vbNullString Then
        strText = Sentence(lngIndex - 1)
      Else
        strText = strText & vbCr & Sentence(lngIndex - 1)
      End If
    End If
  Next lngIndex
  ActiveDocument.SelectContentControlsByTitle("Content Defined").Item(1).Range.Text = strText
  Hide
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote