View Single Post
 
Old 01-18-2019, 01:59 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub ExportList()
Dim i As Long, StrList As String
With Selection.Range
  If .ContentControls.Count = 0 Then Exit Sub
  With .ContentControls(1)
    If .Type = wdContentControlComboBox Or .Type = wdContentControlDropdownList Then
      For i = 2 To .DropdownListEntries.Count
        StrList = StrList & Chr(11) & .DropdownListEntries(i).Text & vbTab & .DropdownListEntries(i).Value
      Next
    End If
  End With
  .Characters.Last.InsertBefore StrList
End With
End Sub
and:
Code:
Sub ImportList()
Dim i As Long, StrList As String, Rng As Range, t As Long
With Selection.Range
  If .ContentControls.Count = 0 Then Exit Sub
  If .Characters.Last = vbCr Then .End = .End - 1
  With .ContentControls(1)
    t = .Type
    If t = wdContentControlComboBox Or t = wdContentControlDropdownList Then
      Set Rng = Selection.Range
      Rng.Start = .Range.End
      .DropdownListEntries.Clear
      For i = 1 To UBound(Split(Rng.Text, Chr(11)))
        .DropdownListEntries.Add Text:=Split(Split(Rng.Text, Chr(11))(i), vbTab)(0), _
          Value:=Split(Split(Rng.Text, Chr(11))(i), vbTab)(1)
      Next
      .Type = wdContentControlText
      .Type = t
      'Rng.Text = vbNullString
    End If
  End With
End With
End Sub
It is assumed the content control is followed by a paragraph break, which must be included in the selection for export. The content control and entry list must be re-selected for import. Do not delete the exported tabs unless the entire entry is deleted; any new entries must likewise contain a tab. The commented-out:
'Rng.Text = vbNullString
can be used to automatically delete the list once it's been imported.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote