Solved

Wrong macro is activated when text is hidden

Posted on 2014-04-27
3
273 Views
Last Modified: 2014-04-27
I have the following text in a MS Word document:
{MACROBUTTON ToBeAddressed To be considered at a future visit}
	Medication changes:
	Add stretches, exercises
	Referal to: 
	Tobacco use: 
{MACROBUTTON Medications Medications}: 

Open in new window

When the text
{MACROBUTTON ToBeAddressed To be considered at a future visit}
	Medication changes:
	Add stretches, exercises
	Referal to: 
	Tobacco use: 

Open in new window

is hidden and I click on the field {MACROBUTTON Medications Medications} is clicked, the macro ToBeAddressed is activated instead of the macro Medications.

I have fixed this problem by adding this code(ToBeAddressed is in a bookmark called RecommendToBeAddressed):
Sub ToBeAddressed()
    If ActiveDocument.Bookmarks("RecommendToBeAddressed").Range.Font.Hidden = True Then
        Medications
        Exit Sub
    End If

Open in new window

Which runs the Medications sub instead. But I am constantly running into this problem and I wonder if there is a better way to handle it?
0
Comment
Question by:thenelson
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40026024
Your workaround to this undocumented feature (i.e. bug) looks as good as any other.

One alternative would be to insert a non-hidden space in front of the second macrobutton field.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40026042
Actually if you put an unhidden space at the end at any of the intermediate lines, it would still work, but be completely unseen (without the slight indent that would result from my first suggestion).
0
 
LVL 39

Author Closing Comment

by:thenelson
ID: 40026314
I can't use an unhidden space at the end at any of the intermediate lines because all the lines between
     {MACROBUTTON ToBeAddressed To be considered at a future visit}
and
     {MACROBUTTON Medications Medications}:
are hidden.

But taking your idea, I placed a no width non break character (in special characters) in front of the
     {MACROBUTTON Medications Medications}:
and that took care of it. The no width non break character does not show up unless show all characters is selected and it does not print.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now