Content Control Range (Inhaltsteuerelement (Word) in Textmarke einschließen)

  • Word

    Content Control Range (Inhaltsteuerelement (Word) in Textmarke einschließen)

    Hallo,

    ich hoffe dass mir jemand helfen kann. Ich habe eine Word Vorlage mit UserForm. In der UserForm wird ein Textfeld ggfls. (wenn CheckBox geklickt ist) angezeigt. Wenn das Textfeld angezeigt wird, dann soll im Dokument einmal links der Inhalt des Textfeldes "normal" stehen [soweit, so gut] und rechts daneben soll der Inhalt als Default-Text in einem Steuerelement gezeigt werden [klappt inzwischen auch].

    Das Problem ist jetzt, dass wenn man die UserForm erneut ausführt, dann möchte ich dass das eingefügte durch das neue ersetzt wird. Das mache ich indem bei der ersten Ausführung sofort eine neue Textmarke erstellt wird und den eingefügten Text "umschließt". Das klappt mit normalen Text auch alles Prima, aber bei dem Steuerelement scheitere ich nun. Bei dem Steuerelement bleibt die Textmarke insich geschlossen (also Anfang = Ende) und steht vor dem Steuerelement.

    Irgendwie müsste es doch möglich sein dass ich den Range des Steuerelements anspreche, oder? Vielen Dank.

    Visual Basic-Quellcode

    1. Dim objCC As ContentControl
    2. If TextBox1.Visible = True Then
    3. If ActiveDocument.Bookmarks.Exists("Feld") Then
    4. Set Marke1 = ActiveDocument.Bookmarks("Feld").Range
    5. Marke1.Text = TextBox1.Text & ":"
    6. ActiveDocument.Bookmarks.Add Name:="Feld", Range:=Marke1
    7. End If
    8. If ActiveDocument.Bookmarks.Exists("Feld2") Then
    9. Set Marke2 = ActiveDocument.Bookmarks("Feld2").Range
    10. Set Marke3 = ActiveDocument.Bookmarks("Feld3").Range
    11. Set objCC = Marke2.ContentControls.Add(wdContentControlText)
    12. objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
    13. objCC.Title = TextBox1.Text
    14. ???
    15. ActiveDocument.Bookmarks.Add Name:="Feld2", Range:=???


    Meine Gehversuche sind bis jetzt alle gescheitert! Hier mal meine Gehversuche die jetzt gerade als Kommentare in meinem Code rumlungern...

    Visual Basic-Quellcode

    1. Dim objCC As ContentControl
    2. If TextBox1.Visible = True Then
    3. If ActiveDocument.Bookmarks.Exists("Feld") Then
    4. Set Marke1 = ActiveDocument.Bookmarks("Feld").Range
    5. Marke1.Text = TextBox1.Text & ":"
    6. ActiveDocument.Bookmarks.Add Name:="Feld", Range:=Marke1
    7. End If
    8. If ActiveDocument.Bookmarks.Exists("Feld2") Then
    9. Set Marke2 = ActiveDocument.Bookmarks("Feld2").Range
    10. Set Marke3 = ActiveDocument.Bookmarks("Feld3").Range
    11. Set objCC = Marke2.ContentControls.Add(wdContentControlText)
    12. objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
    13. objCC.Title = TextBox1.Text
    14. 'ActiveDocument.Bookmarks("Feld2").Delete
    15. 'If ActiveDocument.ContentControls.Count > 3 Then
    16. 'ActiveDocument.Bookmarks("Feld3").Select
    17. Set myRange = ActiveDocument.ContentControls.Item(4).Range
    18. 'End If
    19. 'Dim WD As Word.Application
    20. 'WD = New Word.Application
    21. 'Dim wTable As Word.Table
    22. 'Set wTable = WD.ActiveDocument.Tables.Item(0)
    23. 'wTable.Cell(1, 1).Select()
    24. 'ActiveDocument.Tables(1).Rows(3).Cells(3).Select
    25. 'Selection.InsertAfter Text:="The end."
    26. 'Set Marke3 = objCC.Range
    27. 'Set Marke2 = ActiveDocument.objCC(TextBox1.Text).Range
    28. 'Muss noch überarbeitet werden!
    29. 'Selection.Words.Last.Next.Select
    30. 'ActiveDocument.Bookmarks("Feld2").Range.Characters.Last.Select
    31. 'Selection.Collapse wdCollapseStart
    32. 'Selection.TypeText "Material below is confidential."
    33. 'Set oContentControl = SelectedContentControl
    34. 'Set oContentControl = ActiveDocument.ContentControls(1).Range
    35. 'Set oContentControl = objCC.Range
    36. 'oContentControl.Collapse Direction:=wdCollapseStart
    37. ActiveDocument.Bookmarks.Add Name:="Feld2", Range:=myRange
    38. End If
    39. End If