Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2017, 07:42 AM
Basti089 Basti089 is offline Check Box to have Paragraphas appear/disappear Windows 10 Check Box to have Paragraphas appear/disappear Office 2016
Novice
Check Box to have Paragraphas appear/disappear
 
Join Date: Oct 2017
Posts: 1
Basti089 is on a distinguished road
Default Check Box to have Paragraphas appear/disappear


Hello everyone,

I am currently working on a contract template.
By clicking on a check box for additional services, certain paragraphs shall appear/disappear in the contract.
e.g. by clicking on the checkbox "Hosting" in a software contract, additional terms for hosting services shall appear in the end of the contract.

I have and ActiveX-Checkbox. But how can I link it in the VBA to a certain text paragraph? Shall this paragraph be a bookmarked Text oder a RichText-ContentControl?

let's start with this:
Private Sub CheckBox1_Click()

End Sub

Private Sub CheckBox2_Click()

End Sub

Private Sub CheckBox3_Click()

End Sub

I am no advanced Microsoft User, however I'd like to learn more on VBA etc.

Any help appreciated.

Thank you in advance

Sebastian
Reply With Quote
  #2  
Old 11-04-2017, 10:16 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

Hi

You can use either a bookmark or a content control, that's entirely up to you and how you structure the document.

To hide the text in a content control:
ActiveDocument.ContentControls.Item(1).Range.Font. Hidden=1

To show the text in a content control:
ActiveDocument.ContentControls.Item(1).Range.Font. Hidden=0

To hide text in a bookmark range:
ActiveDocument.Bookmarks("BookmarkName").Range.fon t.hidden=1

To show text in a bookmark range:
ActiveDocument.Bookmarks("BookmarkName").Range.fon t.hidden=0

To hide the hidden fonts from view:
Activewindow.View.ShowHiddenText = False
ActiveWindow.View.ShowAll=False

If you toggle show/hide button you will still be able to see the hidden text, but it won't print.

If you want the text completely removed, use bookmark ranges and input contents by automating autotext entries.

Let me know if you need help with the later.
Reply With Quote
  #3  
Old 11-04-2017, 01:44 PM
macropod's Avatar
macropod macropod is offline Check Box to have Paragraphas appear/disappear Windows 7 64bit Check Box to have Paragraphas appear/disappear Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Simply toggling the font's hidden property is unreliable at best. Depending on how the user has Word configured, the text may remain visible and, even if it doesn't, might print anyway.

To do this properly, you need to conditionally insert/delete the text - including any formatting. One way is to use field coding (but even that is susceptible to unexpected behaviour if the user has word configured to display the field codes and/or print them). The safest way is to either hard-code the conditional content into a macro or a separate reference document, but that is also the least convenient approach.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #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
  #5  
Old 11-05-2017, 12:51 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

Sebastian.. the structure of your document is so important to get this working.

Can you attach a document with dummy text? It's hard to work out a full solution without analysing the template. Thanks. (The stub may help with what you can do, it's the how that's important and that really depends on the design.)
Reply With Quote
Reply



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