Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2017, 09:08 AM
Dr. Z Dr. Z is offline Macro to hide/unhide text to call variable bookmarks Windows 10 Macro to hide/unhide text to call variable bookmarks Office 2010 64bit
Novice
Macro to hide/unhide text to call variable bookmarks
 
Join Date: May 2017
Posts: 2
Dr. Z is on a distinguished road
Default Macro to hide/unhide text to call variable bookmarks

Howdy,



What I want to do:
Create a button on a MS word document that when clicked will show/hide text.

What I did:
1. created a button using the macro {Macrobutton Mymacro Show/Hide}

2. Bookmarked series of text under "bookmark1", "bookmark2", etc.

3. I can create a macro for each bookmarks:
Code:
Sub MYMACRO()
ActiveDocument.Bookmarks(bookmark1).Range.Font.Hidden = Not ActiveDocument.Bookmarks(bookmark1).Range.Font.Hidden
End Sub
This is very crude but I am not a full-time programmer.

My question:
Instead of creating a macro for each bookmark, is there a way for the macro to act as a function and with a variable?

What I want to do is basically make a variable macro, make the macrobutton call to a specific bookmark and have the macro be applied to that bookmark. Instead of writing a different macro with a different bookmark each time, I just want to create a button that will apply the macro to the variable bookmark called each time.

The final purpose is to show/hide 200 pages of text into 50.

I attached an example of what I have done.
I was wondering if it was possible to make OBERON's speech hidden on button toggle without having to write a new line of macro code.

Cheers!
Attached Files
File Type: docm MS Word Spoiler example.docm (21.2 KB, 18 views)
Reply With Quote
  #2  
Old 05-26-2017, 09:01 PM
gmayor's Avatar
gmayor gmayor is offline Macro to hide/unhide text to call variable bookmarks Windows 10 Macro to hide/unhide text to call variable bookmarks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The short answer is no. You will need additional code to do this with a separate macro for each macrobutton field. But you can simplify it - see attached.
Attached Files
File Type: docm MS Word Spoiler example2.docm (25.2 KB, 53 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-27-2017, 08:20 PM
Dr. Z Dr. Z is offline Macro to hide/unhide text to call variable bookmarks Windows 10 Macro to hide/unhide text to call variable bookmarks Office 2010 64bit
Novice
Macro to hide/unhide text to call variable bookmarks
 
Join Date: May 2017
Posts: 2
Dr. Z is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
The short answer is no. You will need additional code to do this with a separate macro for each macrobutton field. But you can simplify it - see attached.
That does make my task easier since now it can be controlled by 1 huge macro instead of several.

I came across an idea concerning the bookmarks. Can I make a degenerate macro that will essential apply itself to the next bookmark in-text?

So if I put the button at position... let's say line 32 and a bookmark is present at line 33 and 44; could the macro simply apply itself to the next available bookmark by line?

Thank you again for your reply. It is much appreciated.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to hide/unhide text to call variable bookmarks Hide / unhide Rows NullVBA Excel Programming 4 12-09-2015 05:10 AM
Hide/Unhide Text Based on Drop Down Selection gw1500se Word 3 02-19-2015 12:17 PM
Macro to hide/unhide text to call variable bookmarks Hide/Unhide a Block of Text Based on Choice Selection inquirer Word VBA 7 09-22-2014 04:41 PM
Hide/Unhide pictures maloneb PowerPoint 1 01-18-2012 03:34 PM
Macro to hide/unhide text to call variable bookmarks Unhide and Re-hide in Excel 2003 thorgal67 Excel 1 07-16-2009 07:06 AM

Other Forums: Access Forums

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