+ Reply to Thread
Results 1 to 6 of 6

Is there a 'tag'-like attribute anywhere in the word object model

  1. #1
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Is there a 'tag'-like attribute anywhere in the word object model

    One of the delights of Access controls (and other controls, too) is the availability of a Tag attribute, which allows the programmer to stash away data useful to the programmer, and guaranteed not to be used by Microsoft!

    I'm engaging in a situation where I will, for a short while, have three different documents open (which could, in reality, all be the same document). I'm opening one as HostDoc, one as SourceDoc, and one as TargetDoc. I'm building a test routine to simply display the names of the open documents, and which is the ActiveDocument at the time.

    I have not been able to find Tag as an attribute of the Document object (boo), but would dearly love to be able to print the Documents collection and get what the logical name of the codument is (the name I'm using in the source code. If we call this hypothetical attribute SuperTag, then I'd be able, when I open the document to say

    Please Login or Register  to view this content.
    That way I don't have to waste coding and debugging time figuring out which I'm working with (some of these documents may be closed and reopened during the course of the program). Does anyone have any ideas how I might accomplish this? One totally off the wall idea would be to have a non-displayed form with three controls, and to stash into the tag of those controls the name of the source document, but (a) that does not respect the actual Documents collection, and (b) returns the document name (which I can already get to), and not the path to the document (the name of the document in the code module.

    Thanks, in advance, for any suggestions (including "Give Up!")

    Tony

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Is there a 'tag'-like attribute anywhere in the word object model

    Custom document properties?
    Last edited by shg; 04-07-2016 at 04:31 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Is there a 'tag'-like attribute anywhere in the word object model

    I encountered these while browsing a document a long time ago and in what felt like another galaxy. However, I gave it a look, and indeed they are present. So....

    I set up a macro recording session to capture the steps necessary.


    NOTHING

    OK, let's take a look at the object model for Document. Sure enough there is CustomDocumentProperties (nothing about non-custom DocumentProperties). No type given, just Object. Really helpful. However, in the model (using F2) there are entries for CustomProperties, Custom Property, DocumentProperties and DocumentProperty.

    OK, not too many possibilities, let's throw some code at it:

    Please Login or Register  to view this content.
    It ran - and found the single custom property I had created manually (while trying to record the macro). OK, Let's redeclare PPInstance as a CustomProperty:

    Please Login or Register  to view this content.
    OK - an entry in CustomDocumentProperties does indeed seem to be a DocumentProperty. Let's see if we can change the values:

    Please Login or Register  to view this content.
    Glory be! It works. Only problem is that I have to create the CustomProperty manually. I wonder if I can add an entry.
    (Short cut)
    Browsing the MSDN site for info on this, I got:
    Please Login or Register  to view this content.
    Hmm, I read the Type value as an integer, but it wants an Object? Turns out there are objects to specify the type (a simnple constant would be fartoo easy, I guess.
    The description under the example in MSDN says msoPropertyTypeString should work.

    Please Login or Register  to view this content.
    The Add fails with an automation error (long negative number signifying nothing).

    I'm stumped - perhaps it's time for an adult beverage. If anyone has any ideas, or has done this before, some code examples would be great......

    Tony

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Is there a 'tag'-like attribute anywhere in the word object model

    Macropod will be along by and by. In the meanwhile, here's some code I use to set custom ducument properties in a proposal template:

    Please Login or Register  to view this content.
    Last edited by shg; 04-07-2016 at 06:42 PM.

  5. #5
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Is there a 'tag'-like attribute anywhere in the word object model

    For code to add & update custom document properties, see: https://support.microsoft.com/en-us/kb/212618
    Word also has document variables that can be used in much the same way.

    The essential difference is that custom document properties are UI-accessible whereas document variables are not.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Is there a 'tag'-like attribute anywhere in the word object model

    Thanks, shgand Paul,

    I'll explore this and get back to you.

    Tony

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel's Object Model
    By nygwnj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2014, 07:08 AM
  2. ==> HOW find specif word on cells and attribute a logic value ??
    By WILKER in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2012, 11:06 PM
  3. Guidance on which Object Model to use
    By SMB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2011, 03:19 AM
  4. Unpublished Object Model Code
    By Jim JBC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2008, 09:25 PM
  5. Dynamic Object Attribute
    By gabch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2006, 01:35 PM
  6. [SOLVED] Confusion about how the Window object fits into the Excel object model
    By Josh Sale in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-18-2005, 10:06 AM
  7. [SOLVED] Excel 2002 Object Model
    By Hiep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2005, 09:06 PM
  8. Chart Object Model
    By Joe Maki in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1