PDA

View Full Version : Solved: Toggle button to show hide bookmark(s)



Flunked
10-05-2009, 04:45 AM
I would be very, very grateful if somebody could help me. I have a document with a list of questions and answers. I have bookmarked the answers and I would like a toggle button to be displayed against each question to allow the user to view only the answer they are interested in.

I have searched many many forums and cannot get the vba code for this, and my VBA is still very much at the novice period can somebody please help me.

fumei
10-05-2009, 12:17 PM
You mean like this?

Flunked
10-05-2009, 12:22 PM
Yes, I mean something very similar... I am also wondering if the toggle button can change text for instance it says show and then hide... I can only do this for one button... I don't get how you managed it for more than one button... I cannot check the VBA is passowrd protected

fumei
10-05-2009, 12:46 PM
It is not really a toggle button (although it acts like one). It is an ActiveX commandbutton. Therefore, clicking it executes instructions. What those instructions are is whatever you code for it.

In this case:Private Sub cmdAnswer1_Click()
ActiveDocument.Bookmarks("Q1").Range _
.Font.Hidden = Not ActiveDocument.Bookmarks("Q1").Range _
.Font.Hidden
End Sub
The _Click event of cmdAnswer1 - the commandbutton with the .Caption of "Answer 1" - simply flips the .Font.Hidden state to whatever it is NOT.

So, if it is True (thus Hidden), it becomes False. if it is False (thus not Hidden), it becomes True (Hidden).

"I don't get how you managed it for more than one button"

By putting the code in for each _Click event.

Flunked
10-05-2009, 12:52 PM
I can't thank you enough - I only started learning VBA yesterday you managed to perform this with a few lines of code. To make this work with one button I had about 15 lines of code.

fumei
10-05-2009, 01:08 PM
You are welcome.

"I only started learning VBA yesterday"

Really? You are biting off chunks if you are starting with trying to use ActiveX controls. For what it is worth, here is the file with the VBE unlocked for you. However, there is nothing more than what I posted in the previous post. Just a second _Click event procedure for the other ActiveX control ("Answer 2").

fumei
10-05-2009, 01:11 PM
You know of course that it is just take three clicks, and an OK, for anyone to be able to see all of your Hidden text?

Flunked
10-05-2009, 01:19 PM
I am aware people can view hidden text if they edit the options. However the people who initially read this document said they was to much text, hence why I want to hide the answers. No chance of them altering any settings :)

Yes to the really? I know how to use html, SQL but have no experience with VBA whatsoever. I am not starting to use Access, Excel and Word more so it is something I need to learn. I don't foresee microsoft implementing VB.Net in any new office releases!

fumei
10-05-2009, 01:35 PM
"I don't foresee microsoft implementing VB.Net in any new office releases!"

Who knows? I would not be too sure about that.

fumei
10-05-2009, 01:37 PM
BTW: if this is resolved, please mark this thread as Solved. Use the Thread Tools at the top.

fumei
10-06-2009, 11:45 AM
You have cross-posted this at Tek-Tips, although in that one you ask about checkboxes doing this. Here, you ask about buttons.

1. It is considered impolite to cross-post and not tell us.

2. New demo attached using a checkbox, and altering the contents of the bookmark. There is no Hidden aspect to the font, so there are no issues regarding changing the Options so the user can see the text, nor any issue with printing.

This route is the one suggested by macropod (at Tek-Tips), and IMO is - from a design POV - the better route.

fumei
10-06-2009, 11:52 AM
Actually, to see why I think it is better, try this:

1. turn OFF show Hidden text (Tools > Options > View tab)

2. click the Show/Hide button on and off.

Now, is that not a little bizarre? This is because of the way Word handles the visibility of Hidden text.