View Single Post
 
Old 10-10-2021, 03:42 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,978
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

This is the macro and sample docs which align with it.
Code:
Sub SelectSnippetFiles3()
  Dim dlgFD As FileDialog, FileChosen As Integer, i As Integer
  Dim DocSrc As Document, DocTgt As Document, sTitle As String, rngTgt As Range, rngSrc As Range
  Dim ccTgt As ContentControl, ccSrc As ContentControl, ccsSrc As ContentControls
  
  Set dlgFD = Application.FileDialog(msoFileDialogFilePicker)
  With dlgFD
    .InitialView = msoFileDialogViewList
    .AllowMultiSelect = True
    FileChosen = .Show
  
    If FileChosen = -1 Then
      Set DocTgt = ActiveDocument
      For Each ccTgt In DocTgt.SelectContentControlsByTag("Snip")
        ccTgt.Range.Text = ""      'empty CC before refilling
      Next ccTgt
      'Application.ScreenUpdating = False
      For i = 1 To dlgFD.SelectedItems.Count
        Debug.Print dlgFD.SelectedItems(i)
        Set DocSrc = Documents.Open(dlgFD.SelectedItems(i))
        For Each ccSrc In DocSrc.SelectContentControlsByTag("Snip")
          sTitle = ccSrc.Title
          Set rngSrc = ccSrc.Range
          rngSrc.Select
          For Each ccTgt In DocTgt.SelectContentControlsByTitle(sTitle)
            Set rngTgt = ccTgt.Range
            If Not ccTgt.ShowingPlaceholderText Then rngTgt.Collapse Direction:=wdCollapseEnd
            rngTgt.FormattedText = rngSrc.FormattedText
          Next ccTgt
        Next ccSrc
        DocSrc.Close SaveChanges:=False
      Next i
      'Application.ScreenUpdating = True
    End If
  End With
 End Sub
Attached Files
File Type: dotm MasterTemplate.dotm (31.1 KB, 17 views)
File Type: docx SnippetDoc.docx (22.0 KB, 11 views)
File Type: docx SnippetDoc2.docx (21.5 KB, 11 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote