Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 14 Oct 2008 09:04:04 -0700,    group: microsoft.public.word.vba.general        back       


ContentControls ID   
We should be able to set the ContentControls ID so that it can be referenced 
from code. i.e. ThisDocument.Range.ContentControls("MyCC")

Thanks for your consideration.

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the 
suggestions with the most votes. To vote for this suggestion, click the "I 
Agree" button in the message pane. If you do not see the button, follow this 
link to open the suggestion in the Microsoft Web-based Newsreader and then 
click "I Agree" in the message pane.

http://www.microsoft.com/office/community/en-us/default.mspx?mid=4394d2ea-bfce-416e-8b38-aa5f72880e97&dg=microsoft.public.word.vba.general
date: Tue, 14 Oct 2008 09:04:04 -0700   author:   KWarner

Re: ContentControls ID   
You can't set the CC unique ID as it is assigned automatically when
the CC is created.  You can get the ID with:

Sub GetUniqueID()
'Click on the CC tab to select the CC
MsgBox Selection.ContentControls(1).ID
End Sub

And then reference it is code with:

Sub SetCCContentByID()
ThisDocument.ContentControls("242079516").Range.Text = "Some text
here"
End Sub



On Oct 14, 12:04 pm, KWarner 
wrote:
> We should be able to set the ContentControls ID so that it can be referenced
> from code. i.e. ThisDocument.Range.ContentControls("MyCC")
>
> Thanks for your consideration.
>
> ----------------
> This post is a suggestion for Microsoft, and Microsoft responds to the
> suggestions with the most votes. To vote for this suggestion, click the "I
> Agree" button in the message pane. If you do not see the button, follow this
> link to open the suggestion in the Microsoft Web-based Newsreader and then
> click "I Agree" in the message pane.
>
> http://www.microsoft.com/office/community/en-us/default.mspx?mid=4394..
date: Tue, 14 Oct 2008 12:31:04 -0700 (PDT)   author:   Greg Maxey

Re: ContentControls ID   
That's just my point. I don't want to have to click on it to get it's ID. For 
instance, if CC("qty") is changed, then I want to be able to change 
CC("amtLeft") from code. I know this example is not really suited for word, 
but I am working on a form template where that type of scenario would come in 
very handy. As it is, I have to do some workarounds to find the CC that I 
want to change from code (and make sure I get the right one). Besides that, 
If I wanted to go through and get each CC's ID it still wouldn't be very good 
programming practices, what with descriptive names and all. Somehow 
CC("138943") doesn't mean as much to me in code as CC("TheOneIwant") does.
While we're on the subject, It would be nice if we could give out Tables a 
unique name also.

> You can't set the CC unique ID as it is assigned automatically when
> the CC is created.
date: Tue, 14 Oct 2008 16:08:04 -0700   author:   KWarner

Re: ContentControls ID   
Then why don't you use the CC.Title:

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel 
As Boolean)
Select Case CC.Title
  Case Is = "The One I Want (qty.)"
  If IsNumeric(CC.Range.Text) Then
    ThisDocument.SelectContentControlsByTitle("The One I Want 
(amt.)").Item(1).Range.Text = Val(CC.Range.Text) * 4
  Else
    MsgBox "The value in the qty. control must be numeric"
  End If
End Select
End Sub



KWarner wrote:
> That's just my point. I don't want to have to click on it to get it's
> ID. For instance, if CC("qty") is changed, then I want to be able to
> change CC("amtLeft") from code. I know this example is not really
> suited for word, but I am working on a form template where that type
> of scenario would come in very handy. As it is, I have to do some
> workarounds to find the CC that I want to change from code (and make
> sure I get the right one). Besides that, If I wanted to go through
> and get each CC's ID it still wouldn't be very good programming
> practices, what with descriptive names and all. Somehow CC("138943")
> doesn't mean as much to me in code as CC("TheOneIwant") does. While
> we're on the subject, It would be nice if we could give out Tables a
> unique name also.
>
>> You can't set the CC unique ID as it is assigned automatically when
>> the CC is created.

-- 
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org

McCain/Palin '08 !!!
date: Tue, 14 Oct 2008 19:29:11 -0400   author:   Greg Maxey RrOMEOgOLF

Re: ContentControls ID   
I do. Unfortunately, you can't direct reference a CC using it's title. You 
have to loop through all of them in the doc or table or wherever. And besides 
that, the CC.Title doesn't have to be unique. You can have 15 different CC's 
all titled "myName". I don't understand why you think the way it is is such a 
great thing. As far as I know, a ContentControl is the only (or one of the 
very, very few) objects that can't be assigned a name/ID and then referenced 
that way. This was just a suggestion to MS to make CC's as easy to use as 
other objects.
I really would like to know why you believe the way CC's are assigned a 
number ID is good and how it benefits the developer.

> Then why don't you use the CC.Title:
>
date: Tue, 14 Oct 2008 16:58:01 -0700   author:   KWarner

Re: ContentControls ID   
Wait a minute.  I didn't say anything was "such a great thing."  I simply 
tried to offer you some alternatives that might work since what you suggest 
and want doesn't?

As for getting serious attention from Microsoft on your suggestion I won't 
hold my breathe.  Hold yours if you want to but CCs are riddled with bugs as 
it is.  I doubt they will give serious attention to making them better 
before they give some attention to making them work. From what I can't see 
they aren't doing much about that.

I am not implying that you are not a serious, highly intelligent developer. 
I'm neither, but I have spent many, many hours trying make something useful 
out of ContentControls and this could be a stretch but perhaps you don't 
understand them as well as you think.

What do you mean by "can't be assigned a name/ID and then referenced that 
way?"  and  "You have to loop through all of them in the doc or table or 
wherever?".

We both know it can't be assigned an ID (your losing sleep over it and I 
don't care) but it can certainly be assigned a name (If you are willing to 
let a title be a name.)

Sub AddTitledCC()
Dim oCC As ContentControl
Set oCC = ThisDocument.ContentControls.Add(wdContentControlText, 
Selection.Range)
oCC.Title = "CCTitle"
End Sub

Fair enough?

Then:

Sub ReferenceCCByTitle()
ThisDocument.SelectContentControlsByTitle("CCTitle").Item(1).Range.Text = 
"Did this not reference the title"
End Sub

Is that not referencing the CC by name in code?

As you know the a you can have multiple CCs with the same title.  If that is 
the case then if you want to want to work with one of them (any of them my 
title) then you have to include its Item index.

If you had 15 different CCs titled "myName" then it seems you would want all 
of them to contain the same data.  After all, my name is Greg if it appears 
on the first page or last page of a document and I assume yours wouldn't 
chang between pages.  If that is the case then the all the myName CCs should 
be mapped to customXML so that if you change one with code then they all 
change.




KWarner wrote:
> I do. Unfortunately, you can't direct reference a CC using it's
> title. You have to loop through all of them in the doc or table or
> wherever. And besides that, the CC.Title doesn't have to be unique.
> You can have 15 different CC's all titled "myName". I don't
> understand why you think the way it is is such a great thing. As far
> as I know, a ContentControl is the only (or one of the very, very
> few) objects that . This was just a suggestion to MS to make CC's as easy 
> to
> use as other objects.
> I really would like to know why you believe the way CC's are assigned
> a number ID is good and how it benefits the developer.
>
>> Then why don't you use the CC.Title:

-- 
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org

McCain/Palin '08 !!!
date: Tue, 14 Oct 2008 20:44:39 -0400   author:   Greg Maxey RrOMEOgOLF

Re: ContentControls ID   
This thread started out as a suggestion for MS. They asked for suggestions, 
and that's all this was. I agree that CC's still need some serious attention.
> 
> As for getting serious attention from Microsoft on your suggestion I won't 
> hold my breathe.  

Thank you for this. This is exactly what I was looking for.

> > ThisDocument.SelectContentControlsByTitle("CCTitle").Item(1).Range.Text = 
> "Did this not reference the title"
date: Wed, 15 Oct 2008 02:24:01 -0700   author:   KWarner

Re: ContentControls ID   
You weren't the first that has spent time and frustration looking for it. 
Glad I could help.


KWarner wrote:
> This thread started out as a suggestion for MS. They asked for
> suggestions, and that's all this was. I agree that CC's still need
> some serious attention.
>>
>> As for getting serious attention from Microsoft on your suggestion I
>> won't hold my breathe.
>
> Thank you for this. This is exactly what I was looking for.
>
>>> ThisDocument.SelectContentControlsByTitle("CCTitle").Item(1).Range.Text
>>> =
>> "Did this not reference the title"

-- 
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org

McCain/Palin '08 !!!
date: Wed, 15 Oct 2008 07:20:50 -0400   author:   Greg Maxey RrOMEOgOLF

Re: ContentControls ID   
I am not sure of the exact path that you follow to get to the screen in 
which you make a post that contains the "canned" text

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

but they do show up here from time to time.  The real purpose of these 
newsgroups however is to obtain peer support in the use of the software.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"KWarner"  wrote in message 
news:047EBFCA-0282-426F-8C1C-5A1743DA080D@microsoft.com...
> This thread started out as a suggestion for MS. They asked for 
> suggestions,
> and that's all this was. I agree that CC's still need some serious 
> attention.
>>
>> As for getting serious attention from Microsoft on your suggestion I 
>> won't
>> hold my breathe.
>
> Thank you for this. This is exactly what I was looking for.
>
>> > ThisDocument.SelectContentControlsByTitle("CCTitle").Item(1).Range.Text 
>> > =
>> "Did this not reference the title"
date: Thu, 16 Oct 2008 10:04:04 +1000   author:   Doug Robbins - Word MVP

Re: ContentControls ID   
Hi =?Utf-8?B?S1dhcm5lcg==?=,

> Besides that, 
> If I wanted to go through and get each CC's ID it still wouldn't be very good 
> programming practices, what with descriptive names and all. Somehow 
> CC("138943") doesn't mean as much to me in code as CC("TheOneIwant") does.
> While we're on the subject, It would be nice if we could give out Tables a 
> unique name also.
>
1. There's a valid reason for ContentControl IDs to be read-only. The ID is a 
GUID, which means the chances of it ever conflicting with any other ID value are 
slim to non-existant. This was a consious design decision, so I very much doubt 
it will be changed.

2. If I needed to access ContentControls by ID I'd probably do a *single* loop 
through the document and create a collection that stores the ID and the Title 
(and tag and whatever else is of interest). Then I could reference using (for 
example) the Title which would give me the ID so that I can address the 
contentControl directly. That's valid "programming practice" and one loop 
through a document isn't that resource-intensive...

3. To name a table: Select the table and apply a bookmark to it. Or put it in a 
ContentControl.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply 
in the newsgroup and not by e-mail :-)
date: Mon, 27 Oct 2008 11:15:42 +0100   author:   Cindy M.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us