Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2015, 07:53 AM
Tejas.T Tejas.T is offline ActiveDocument.ContentControls(ID) not working Windows 8 ActiveDocument.ContentControls(ID) not working Office 2010 32bit
Novice
ActiveDocument.ContentControls(ID) not working
 
Join Date: Feb 2015
Posts: 6
Tejas.T is on a distinguished road
Default ActiveDocument.ContentControls(ID) not working

I am using ActiveDocument.ContentControl(ID) method very frequently and it works finie.

But due to some reason, it does not work in Word 2007 in attached document.

ID of that Content Control is 2068831631
But I following statement give error saying, Requested member of collection does not exist
Code:
ActiveDocument.ContentControls("2068831631").Range.Select
Can anybody please tell me what is wrong with that content control?



Thanks.
Attached Files
File Type: docx Content Ctrl problem.docx (18.1 KB, 15 views)
Reply With Quote
  #2  
Old 03-09-2015, 08:44 AM
gmayor's Avatar
gmayor gmayor is offline ActiveDocument.ContentControls(ID) not working Windows 7 64bit ActiveDocument.ContentControls(ID) not working Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Use
Code:
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        If oCC.ID = "2068831631" Then
            oCC.Range.Select
            Exit For
        End If
    Next oCC
instead - which will select it in Word 2007, 2010 and 2013.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-09-2015, 03:51 PM
Tejas.T Tejas.T is offline ActiveDocument.ContentControls(ID) not working Windows 8 ActiveDocument.ContentControls(ID) not working Office 2010 32bit
Novice
ActiveDocument.ContentControls(ID) not working
 
Join Date: Feb 2015
Posts: 6
Tejas.T is on a distinguished road
Default

I have thought of this code but it might not be good for performance.
Is there any reason why ActiveDocument.ContentControls not working?
it works for all other content controls in document, having issue with only this one.

And also this content controls works fine on Word 2010 and 2013.

So the issue is specific to Word 2007 and only this content control.

Thanks for you help.
Reply With Quote
  #4  
Old 03-09-2015, 06:50 PM
gmaxey gmaxey is offline ActiveDocument.ContentControls(ID) not working Windows 7 32bit ActiveDocument.ContentControls(ID) not working Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Tejas,

I am not a mathematician or even a general numbers guy. However, If you look at a bunch of CCs created with Word 2007 I believe the majority of them will have IDs 9 digits long (some may have 10 digits) but none with the first left hand number greater than 1. With Word 2010, CCs are commonly 10 digits long an the left hand number can be greater than 1. There is nothing wrong with the CC, only the Word 2007 object doesn't associate the "larger" ID to the CC. Yes the CCs ID is the ID but that ID doesn't mean anything to the CC collection. You will have to error handle e.g.<

Code:
Sub DemoIssue()
Dim oCC As ContentControl
  On Error GoTo Err_InvalidID
  Set oCC = ActiveDocument.ContentControls(ActiveDocument.ContentControls(1).ID)
  oCC.Range.Select
lbl_Exit:
  Exit Sub
Err_InvalidID:
  Set oCC = W2007CCInvalidID(ActiveDocument.ContentControls(1).ID)
  Resume Next
End Sub
Function W2007CCInvalidID(ByRef strID As String) As ContentControl
Dim lngValidator As Long
Dim oRngStory As Range
Dim oCCTest As ContentControl, oShp As Shape
  'Handles the ContentControl ID errors introduced with Word 2010.
  lngValidator = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  For Each oRngStory In ActiveDocument.StoryRanges
    'Iterate through all linked stories
    Select Case oRngStory.StoryType
      Case 1 To 11
        Do
          On Error Resume Next
          For Each oCCTest In oRngStory.ContentControls
            If oCCTest.ID = strID Then
              Set W2007CCInvalidID = oCCTest
              Exit Function
            End If
          Next oCCTest
          Select Case oRngStory.StoryType
            Case 6, 7, 8, 9, 10, 11
              If oRngStory.ShapeRange.Count > 0 Then
                For Each oShp In oRngStory.ShapeRange
                  On Error GoTo Err_HasText
                  If oShp.TextFrame.HasText Then
                    For Each oCCTest In oShp.TextFrame.TextRange.ContentControls
                      If oCCTest.ID = strID Then
                        Set W2007CCInvalidID = oCCTest
                        Exit Function
                      End If
                    Next oCCTest
                  End If
Err_HasText_ReEntry:
                Next oShp
              End If
            Case Else
              'Do Nothing
          End Select
          On Error GoTo 0
          'Get next linked story (if any)
          Set oRngStory = oRngStory.NextStoryRange
        Loop Until oRngStory Is Nothing
      Case Else
    End Select
  Next
  Set oRngStory = Nothing
  Set oCCTest = Nothing
  Set oShp = Nothing
lbl_Exit:
  Exit Function
Err_HasText:
  Resume Err_HasText_ReEntry
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
content control, content controls, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
ActiveDocument.ContentControls(ID) not working TOC Not Working Gary91 Word 3 01-21-2015 05:52 AM
Updating grouped ContentControls in Word 2010 MGerhard Word VBA 3 08-04-2014 02:34 AM
wordapp.ActiveDocument.SaveAs Not Working KSReynolds Mail Merge 1 07-18-2014 04:03 PM
ActiveDocument.ContentControls(ID) not working Using With ActiveDocument.Tables() SuzeG Word VBA 1 01-08-2014 02:00 PM
ActiveDocument.ContentControls(ID) not working Array into ComboBox + Macro-Text into ActiveDocument Vivi Word VBA 1 01-27-2010 07:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft