View Single Post
 
Old 09-27-2018, 09:33 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg's code is very elegant with the use of a Collection to determine if the code has already hit one of those CCs but it does rely on your consistent usage of the Title property for every CC.

An alternative to consider would be to just lock the CCs which are mapped to the same xpath as already used. There is also no real need to do two passes...
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 9/27/2018
Dim oCC As ContentControl, oCol As New Collection
  On Error Resume Next
  For Each oCC In ActiveDocument.ContentControls
    If aCC.XMLMapping.IsMapped then oCol.Add oCC.XMLMapping.XPath, oCC.XMLMapping.XPath
    oCC.LockContents = Not Err.Number = 0
    Err.Clear
  Next oCC
lbl_Exit:
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote