Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 01-17-2020, 09:07 AM
gmaxey gmaxey is offline Let bookmark check if there are empty bookmarks before and place sentence there? Windows 10 Let bookmark check if there are empty bookmarks before and place sentence there? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Let bookmark check if there are empty bookmarks before and place sentence there? Field Code: Show a value only if bookmark is not empty Cosmo Word 7 08-24-2018 01:46 PM
Let bookmark check if there are empty bookmarks before and place sentence there? Removing spaces in activedocument after empty bookmarks faustino909 Word VBA 2 08-03-2018 01:34 PM
Let bookmark check if there are empty bookmarks before and place sentence there? VBA, Place Sentence in its own Line ilcaa72 Word VBA 6 04-28-2017 07:01 AM
Let bookmark check if there are empty bookmarks before and place sentence there? Trying to read CSV file and place values into word bookmarks Philip1 Word VBA 5 10-27-2016 12:37 AM
Let bookmark check if there are empty bookmarks before and place sentence there? Excel vba to check to check if two columns are empty subspace3 Excel Programming 5 07-09-2015 04:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft