View Single Post
 
Old 03-09-2015, 06:50 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
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