none
What mechanisms are available to mark text ranges with VBA? RRS feed

  • Question

  • Hi all,

    Question: What mechanisms are available to mark text ranges with VBA?

    Background: I want to implement a simple method for implementing conditional text in Word. So I want to be able to mark a range of text using VBA and then optionally make it visible in the document, i.e., make the marking visible also.

    Detail:

    So what are the different ways available for marking (tagging) text?

    1.  Highlighting only?

    2.  Shading only?        Don't like these two   Highlighting and Shading, coz what happens if you then add some of your own Highlighting or Shading.

    (Hope you all understood what I meant by "only".)

    3. Commenting – now that sounds more sophisticated. I can then also label the range.

    4. Bookmarks - also good. I can label the range. But bookmarks easily get deleted by mistake.

    Anything else?

    *** 

    5. Maybe there is a 'tag' property for each character or at least for each paragraph?

    *** 

    Thanks,

    avraham


    Sunday, January 6, 2013 4:46 PM

Answers

  • Hi Avraham

    Bookmarks are a definite possibility; there is no "tag" property of any kind for text in Word. You could use Comments, as well, if you don't mind the user seeing the Comments when the mouse goes over one.

    Another approach would be to create a parallel set of styles and use these to format the ranges you want to be able to "grab". Then all you'd need to do is change the style definition. This would be a good approach if you need to "highlight" all the ranges at the same time. (Whether that's what you want is not clear from your problem description.)

    It would also be possible to put the ranges in Content Controls if we're talking about Word 2007 or later. These can be protected from deletion, but they'll be visible to the user when he works on text inside a content control.


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, January 6, 2013 5:32 PM
    Moderator