View Single Post
 
Old 11-15-2018, 08:27 AM
thuriel thuriel is offline Windows 10 Office 2019
Novice
 
Join Date: Oct 2018
Location: Buenos Aires, Argentina
Posts: 7
thuriel is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
I have been there, too, on both sides

Thank u for helping me, thanks to your example I was able to solve the problem through tags

Code:
Sub list1()
Application.ScreenUpdating = False
Dim strFolder$, strFile$, strDocNm$
strDocNm = ActiveDocument.FullName
strFile = Dir(ActiveDocument.Path & "\list1\*.doc", vbNormal)
Dim oThisdoc As Word.Document
Dim oCC As ContentControl
Dim oCCs As ContentControls

Set oThisdoc = ActiveDocument
Set oCCs = oThisdoc.SelectContentControlsByTag("List1")

    For Each oCC In oCCs
    If oCCs.Count > 0 Then
With oCC
  .DropdownListEntries.Clear
  .Type = wdContentControlText
  .Range.Text = ""
  .Type = wdContentControlDropdownList
  While strFile <> ""
    If strFolder & "\" & strFile <> strDocNm Then
      .DropdownListEntries.Add strFile
    End If
    strFile = Dir()
  Wend
End With
Application.ScreenUpdating = True
End If
Next
End Sub

Sub list2()
Application.ScreenUpdating = False
Dim strFolder$, strFile$, strDocNm$
strDocNm = ActiveDocument.FullName
strFile = Dir(ActiveDocument.Path & "\list2\*.doc", vbNormal)
Dim oThisdoc As Word.Document
Dim oCC As ContentControl
Dim oCCs As ContentControls

Set oThisdoc = ActiveDocument
Set oCCs = oThisdoc.SelectContentControlsByTag("List2")

    For Each oCC In oCCs
    If oCCs.Count > 0 Then
With oCC
  .DropdownListEntries.Clear
  .Type = wdContentControlText
  .Range.Text = ""
  .Type = wdContentControlDropdownList
  While strFile <> ""
    If strFolder & "\" & strFile <> strDocNm Then
      .DropdownListEntries.Add strFile
    End If
    strFile = Dir()
  Wend
End With
Application.ScreenUpdating = True
End If
Next
End Sub
It has been managed to make the most dynamic and still complete the text by means of what is selected in the drop-down list through

Code:
Sub list_to_text()
Dim oThisdoc As Word.Document
Dim oCC As ContentControl
Dim oCCs As ContentControls
Dim sText As String

Set oThisdoc = ActiveDocument
Set oCCs = oThisdoc.SelectContentControlsByTag("List1")



Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
    For Each oCC In oCCs
    If oCCs.Count > 0 Then
    oCC.Range.Select
    oCC.Delete False
    sText = Application.Selection.Text
    End If
Next

                ChangeFileOpenDirectory ActiveDocument.Path & "\List1\"
            Selection.InsertFile FileName:=sText, Range:="", ConfirmConversions:= _
        False, Link:=False, Attachment:=False
            Selection.TypeBackspace
            Selection.MoveRight Unit:=wdCharacter, Count:=1
  
  
End Sub

Last edited by thuriel; 11-15-2018 at 01:53 PM.
Reply With Quote