MS Word, VB6 and VBA: How set a custom flag/object/property/tag to a Range object?

Posted on 2015-01-09
Last Modified: 2015-01-25
Is there a way to assign a user defined something like flag/object/property/tag to a Range object?
Does the Range object has some unused property of Variant/String/Object type which the user could use for its on purpose?

In VB6 for instance, controls have the Tag (string) property, which is not used by VB6 by default, and it can be used for any purpose, such as assigning some data to that control.

So, is there some equivalent for the Range object?
Question by:npaun
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 18

Expert Comment

ID: 40539982
I'd think not. A control is a persistent object whose properties can be written to file, whereas a range is an ephemeral one.
LVL 15

Accepted Solution

DrTribos earned 500 total points
ID: 40539993
I think you might have to look at bookmarks or content controls
LVL 18

Expert Comment

ID: 40540112
For Word there are custom document properties that you can create/edit/delete.
For Excel there is the names collection and cells can be assigned an ID:
"Returns or sets a String value that represents the identifying label for the specified cell when the page is saved as a Web page."
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40540121
You mean CustomDocumentProperties? If I understated correctly, they are document level properties, while I need it for Range object (e.g. selections, Words...)
LVL 18

Expert Comment

ID: 40540159
There is the range.comment object which is part of the tracked changes/review document process.

Selection.Comments.Add Range:=Selection.Range

This creates a review comment that is associated with the range (word, phrase, paragraph) that you want.

You can then do various things with the comment and/or the range it refers to.

Sub test()
Dim myRange As Range
If ActiveDocument.Comments.Count >= 1 Then
    For x = 1 To ActiveDocument.Comments.Count
    Set myRange = ActiveDocument.Comments(x).Range
    Debug.Print myRange, myRange.Start, myRange.End
    Next x
End If
End Sub

Author Comment

ID: 40540221
Thanks for the reply. Yes, I know for the comment property, however it has internal use by Word, and all entries here would be seen in the user comments selection, i.e. these entries would interfere with comments manually and explicitly added by the user itself... I would need a Range property that is "unused" and would not so easily interfere with Word...

Author Comment

ID: 40540240
Thank for the post.
Unfortunately, the ContentControls also severely interfere with the Word normal behavior, it, as intended, ads clearly visible controls in the text...
LVL 15

Expert Comment

ID: 40540873
Yup, aside from that i think it is bookmarks.

Other approaches that I can think of would be very 'hacky'...

1. Delineate range via a portfolio of uniquely named styles all with the same appearance
2. Delineate using table cell
3. Delineate using field codes

But as far as I know bookmarks is the go

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to order an IEnumerable in an ASPX page using VB.Net for the code behind 5 51
Format Transaction Number 19 48
How do I force Tracked changes 6 42
Adding Rows to Grid 4 29
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

739 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