Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-05-2017, 12:28 AM
FionaMcKenzie FionaMcKenzie is offline Check Box to have Paragraphas appear/disappear Windows 10 Check Box to have Paragraphas appear/disappear Office 2016
Novice
 
Join Date: Oct 2017
Location: Surrey, United Kingdom
Posts: 14
FionaMcKenzie is on a distinguished road
Default

Great thanks Paul. I agree.

Sebastian, what I use to do was either bring in the content text from a document resource file to a bookmark location. Or Autotexts are great for content you don't change that you bring in conditionally. So the resource files are for text that may be edited from time to time, autotexts or quickparts are for building blocks.

This stub gives you an idea what you can do. Capture your checkbox events then based on your logic bring in the elements or remove them. (I've just shown bringing them in.)

Unfortunately, Bookmarks can easily be deleted or typed in accidentally in paragraphs.

If you can use a table cell and put the bookmark around the table cell, that is better, i.e. not so easy to accidentally delete.


Sub ImportDocElementsStub()

Dim bCheckBoxA As Boolean, bCheckBoxB As Boolean, bCheckBoxC As Boolean
Dim lRangeStart As Long, lRangeEnd As Long
Dim sResourceFile As String
Dim oDoc As Word.Document
Dim oTemplate As Word.Template
Dim oRange As Word.Range

Const cBookmarkForAutoText As String = "AutotextElement"
Const cBookmarkForResource As String = "ResourceElement"

' Reference if you need it may be to specific document
Set oDoc = ActiveDocument

' You will need to reference the template with the autotexts
' whether that be the template attached to the document
' or a global template
Set oTemplate = oDoc.AttachedTemplate

' The path to your resource file with the text formatted and ready
sResourceFile = "C:\ResourceFile.docx"

' Determine if your checkboxes have been checked or not
bCheckBoxA = True
bCheckBoxB = True
bCheckBoxC = True

If bCheckBoxA Then
Set oRange = oDoc.Bookmarks(cBookmarkForAutoText).Range

' Sample of how to insert a building block
Set oRange = oTemplate.BuildingBlockEntries(cBookmarkForAutoTex t).Insert _
(oRange, RichText:=True)

' Add the bookmark back to the range
oRange.Bookmarks.Add "AutoTextElement"
End If

' Bookmark around a paragraph - NOT IDEAL
If bCheckBoxB Then
lRangeStart = oDoc.Bookmarks(cBookmarkForResource).Start
' So you don't loose the bookmark if around a paragraph
lRangeEnd = oDoc.Bookmarks(cBookmarkForResource).End - 1

' reference to range for text
Set oRange = oDoc.Range(lRangeStart, lRangeEnd)

' Either you can open and copy the data
' or insertfile to a range
oRange.InsertFile FileName:=sResourceFile
End If

'if you can use a table cell, do so!
If bCheckBoxC Then

' Bookmark around a single cell table
Set oRange = oDoc.Bookmarks("TableCellBookmark").Range

oRange.InsertFile sResourceFile
End If

Set oRange = Nothing
Set oTemplate = Nothing
Set oDoc = Nothing

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Box to have Paragraphas appear/disappear Excel vba to check to check if two columns are empty subspace3 Excel Programming 5 07-09-2015 04:45 PM
Multiple Check In/check Out Times big0 Excel 4 09-19-2013 05:02 AM
Check Box to have Paragraphas appear/disappear cannot check/uncheck check box but added check box learn2office Word 1 11-27-2012 02:02 AM
Link word check box to access check box Mrkieth Word 4 01-30-2012 06:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:20 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