Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-29-2012, 04:01 AM
jillapass jillapass is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default Content control titles

Rather than refer to my content controls as .contentcontrol(3) (for example) and I refer to them by the title I have given them.

In some of my documents I have about 100 content controls and using numbers is rather difficult to read.

Thanks
Reply With Quote
  #2  
Old 05-29-2012, 05:31 AM
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 8,484
macropod has a spectacular aura aboutmacropod has a spectacular aura aboutmacropod has a spectacular aura about
Default

Is there an issue here?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 05-29-2012, 05:56 AM
jillapass jillapass is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

Sorry, failed to explain.
I give each of my content controls a title in the properties.
Is it possible for me to update these using the title rather than the number.

eg

I currently have

field = activedocument.contentcontrols(1).range.text

what I want to do is

field = activedocument.contentcontrols("title").range.text

But, this doesn't work.

Is this possible, and if so what should the syntax be.

Thanks
Reply With Quote
  #4  
Old 05-29-2012, 06:11 AM
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 8,484
macropod has a spectacular aura aboutmacropod has a spectacular aura aboutmacropod has a spectacular aura about
Default

AFAIK, the only way to use the title directly is to loop through the collection:
Code:
Dim CCtrl As ContentControl
For Each CCtrl In ActiveDocument.ContentControls
  If CCtrl.Title = "My Title" Then
    'do something
  End If
Next
If you were doing a lot of Content Control processing in code, rather than interactively, you might get a performance improvement if you store the collection in code first:
Code:
Sub Demo()
Dim CCtrlSet As Variant, CCtrl As ContentControl
Set CCtrlSet = ActiveDocument.ContentControls
For Each CCtrl In CCtrlSet
  If CCtrl.Title = "My Title" Then
    'do something
  End If
Next
Set CCtrlSet = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Retrieving content control value jillapass Word VBA 4 05-24-2012 05:07 AM
content control Word 2007 TessaLee Word 2 06-26-2011 11:23 PM
Move to next content control cksm4 Word VBA 12 03-02-2011 08:53 AM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM


All times are GMT -7. The time now is 11:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft