Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2024, 08:17 AM
Rikke Rikke is offline How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2021
Novice
How to hide and show a tabel using bookmark and checkbox
 
Join Date: Apr 2024
Posts: 3
Rikke is on a distinguished road
Default How to hide and show a tabel using bookmark and checkbox

Hello

I am desperately trying to code a word document, but cant get it to work.

I need a tabel to show when a check a certain checkbox.



I am using a bookmark for the tabel.

The checkbox is named "LPja" and the tabel bookmark i named "TabelLP"

I have tryed a number og codes but keep getting error 5941.

What code can I use to get this to work?

I have Office 365, but cant select that.

Thanks in advance.
Reply With Quote
  #2  
Old 04-17-2024, 04:27 PM
Guessed's Avatar
Guessed Guessed is offline How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,989
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Post your code and we can offer suggestions on how to fix it. Also it helps if you attach a cut down version of your doc which has the checkbox, bookmark and table.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 04-18-2024, 05:52 AM
Rikke Rikke is offline How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2021
Novice
How to hide and show a tabel using bookmark and checkbox
 
Join Date: Apr 2024
Posts: 3
Rikke is on a distinguished road
Default

I have tryed a lot. This is the one I am working with right now. It is giving me error 5941.

Private Sub LPja_Click()
If ActiveDocument.FormFields("LPja").CheckBox.Value = True Then
' Vis tabellen
ActiveDocument.Bookmarks("TabelLP").Range.Font.Hid den = False
Else
' Skjul tabellen
ActiveDocument.Bookmarks("TabelLP").Range.Font.Hid den = True
End If
End Sub

I have attached the file, i hope
Attached Files
File Type: docm Test4.docm (66.8 KB, 7 views)
Reply With Quote
  #4  
Old 04-18-2024, 04:57 PM
Guessed's Avatar
Guessed Guessed is offline How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,989
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This would really be better if you were using Content Controls. I think you should either:
1. Change to content controls or
2. Change your checkboxes to option buttons

The only benefit of using legacy fields over Content Controls is the availability of legacy Option buttons and the ability to group them so only one can be turned on at a time. You are trying to replicate that built-in functionality with code because you chose a checkbox instead of an option button.

But doing it with the legacy checkbox field, for that macro you just need a single line
Code:
Private Sub LPja_Click()
  ActiveDocument.Bookmarks("TabelLP").Range.Font.Hidden = Not LPja.Value
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-30-2024, 08:20 AM
Rikke Rikke is offline How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2021
Novice
How to hide and show a tabel using bookmark and checkbox
 
Join Date: Apr 2024
Posts: 3
Rikke is on a distinguished road
Default

Thank you.

I need the option to group and only check one at the time aswell.

I have tryed your macro, but it dos not hide the tabel.

What am I doing wrong? I am putting the macro in to the checkbox, but the tabel stays visible weather or not it is checked.
Attached Files
File Type: docx eks..docx (104.0 KB, 1 views)
Reply With Quote
  #6  
Old 05-01-2024, 07:43 AM
gmaxey gmaxey is online now How to hide and show a tabel using bookmark and checkbox Windows 10 How to hide and show a tabel using bookmark and checkbox Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,432
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

Setting it up is not a walk in the sun (and there is a minor irritant), but the attached document shows and explains a method to do this with mapped content controls and a customXMLPart event monitor.


If anyone looks at this, I would be interested if any other approach to resolve Microsoft's negligence in resolving the long standing issues with the events. There is no (known) logical explanation why the DocumentCCExit event does not fire when when a user moves the mouse from a CC to check or uncheck another CC.


Cross posted: https://www.msofficeforums.com/word-...omxmlpart.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to show/hide checkboxes- always showing bookmark KSmart Word VBA 4 11-07-2023 02:24 PM
Bookmark will not show/hide based on CC Checkbox lord_kaiser Word VBA 1 04-17-2018 01:19 AM
How to hide and show a tabel using bookmark and checkbox How to use checkbox to show/hide bookmarked text? namrehx Word VBA 16 12-14-2017 01:45 PM
How to use checkbox to show and hide bookmarked text? namrehx Word VBA 1 12-12-2017 02:17 PM
How to hide and show a tabel using bookmark and checkbox Show/Hide Text based on Checkbox Selection tammytran105 Word VBA 7 10-02-2014 04:30 PM

Other Forums: Access Forums

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