Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2020, 09:29 AM
lolla70 lolla70 is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Novice
VBA to display/hide Paragraph of a word document
 
Join Date: Mar 2019
Posts: 14
lolla70 is on a distinguished road
Default VBA to display/hide Paragraph of a word document

I have two Checkboxes

Checkbox 1 - Paragraph 1 (Bookmark1)


Checkbox 2 - Paragraph 2 (Bookmark2)

I want the two paragraph to stay visible but when the client choose Checkbox1 then the Checkbox2 - paragraph 2 is hidden and viseversa. Is this possible and easy to do?
Reply With Quote
  #2  
Old 11-11-2020, 09:56 AM
gmaxey gmaxey is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

Probably but what exactly are your trying to do.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-11-2020, 10:11 AM
lolla70 lolla70 is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Novice
VBA to display/hide Paragraph of a word document
 
Join Date: Mar 2019
Posts: 14
lolla70 is on a distinguished road
Default

I have two paragraphs that the client needs to choose from. So if he Click on the checkbox1 I want Checkbox 2 to be hidden, and if he clicked on Checkbox2 I want Checkbox1 to be hidden.
Reply With Quote
  #4  
Old 11-11-2020, 10:21 AM
gmaxey gmaxey is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

And what should happen wrt to the obstinate client who choose neither, or the indecisive client who chooses checkbox1 or checkbox2 and then changes his or her mind?

A alternate method is neither paragraph is shown until the client makes up his or her mind and chooses and give the client a means of changing their mind.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 11-11-2020, 11:06 AM
lolla70 lolla70 is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Novice
VBA to display/hide Paragraph of a word document
 
Join Date: Mar 2019
Posts: 14
lolla70 is on a distinguished road
Default

They need to pick one. If he checked the first one, and then he chnaged his mind then he will uncheck and the checkbox 2 appear and check it.
Reply With Quote
  #6  
Old 11-11-2020, 02:45 PM
gmaxey gmaxey is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

This seems a convoluted process but yes it is certainly possible. See attached document and image.

You will need to create the three different conditions
0) a rich text cc (Titled Result) with both check boxes and text showing
1) a richtext CC (Titled Result1) with Checkbox1 and text only
2) a rich text CC (Titled Result2) with Checkbox 2 and text only and an overall result richtext CC (titled Result) showing both checkboxes and text.

These will have to be mapped to a customXMLpart. Once done, you can remove the Result0, Result1 and Result2 richtext CCs and content.


You will need the following code in the ThisDocument class object:


Code:
Private Sub Document_ContentControlBeforeStoreUpdate(ByVal CC As ContentControl, Content As String)
  Select Case CC.Title
    Case "Checkbox1"
      'Reset so Result CC shows both checkboxes and paragraphs (Result0 node value)
      CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result[1]").Text = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result0[1]").Text
      If CC.Checked Then
        'Remap Result CC to show only checkbox 1 and text (Result1 node value)
        CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result[1]").Text = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result1[1]").Text
      End If
    Case "Checkbox2"
      'Reset so Result CC shows both checkboxes and paragraphs (Result0 node value)
      CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result[1]").Text = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result0[1]").Text
      'Remap Result CC to show only checkbox 2 and text (Result2 node value)
      If CC.Checked Then
        CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result[1]").Text = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Result2[1]").Text
      End If
  End Select
End Sub
Attached Images
File Type: jpg CustomXMLPart.jpg (19.1 KB, 29 views)
Attached Files
File Type: docm Toggle node text.docm (140.9 KB, 13 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by Charles Kenyon; 11-13-2020 at 11:55 AM. Reason: make list more readable
Reply With Quote
  #7  
Old 11-18-2020, 12:00 PM
lolla70 lolla70 is offline VBA to display/hide Paragraph of a word document Windows 10 VBA to display/hide Paragraph of a word document Office 2016
Novice
VBA to display/hide Paragraph of a word document
 
Join Date: Mar 2019
Posts: 14
lolla70 is on a distinguished road
Default

Hi Greg thanks for helping, I tried badly to open your word document but it is not working. I am new to VBA and I couldn't follow your step. So I made something simple and it work. I have another question.

I created the attached document that includes in it a VBA user field to fill the fields in the documents with a bookmark. The VBA will run when you open the document and ask you the questions, anyway. Also, I want the document to be password protected so no one can change anything except the field that is open to them to fill by the VBA. When I protect the document, the VBA doesn't run. Is there a code for that or a solution?
Attached Files
File Type: dotm Checkbox_Demo.dotm (40.0 KB, 8 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document storemaz Word VBA 1 03-13-2020 08:11 AM
VBA to display/hide Paragraph of a word document Text disappear on ms-word 2010 when press "show/hide Paragraph" francescof Word 2 03-27-2019 01:35 AM
Hide and display pictures Ljungwe Drawing and Graphics 1 04-26-2018 04:46 AM
VBA to display/hide Paragraph of a word document Help with Hide/Display of sections of document based on Drop Down selections turnquistcm Word 2 05-03-2017 07:05 PM
VBA to display/hide Paragraph of a word document How to manage (display/hide) parts of the text within a document via table of content Curby Word 2 06-30-2016 12:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:39 AM.


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