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.
Meine Gehversuche sind bis jetzt alle gescheitert! Hier mal meine Gehversuche die jetzt gerade als Kommentare in meinem Code rumlungern...
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
- Dim objCC As ContentControl
- If TextBox1.Visible = True Then
- If ActiveDocument.Bookmarks.Exists("Feld") Then
- Set Marke1 = ActiveDocument.Bookmarks("Feld").Range
- Marke1.Text = TextBox1.Text & ":"
- ActiveDocument.Bookmarks.Add Name:="Feld", Range:=Marke1
- End If
- If ActiveDocument.Bookmarks.Exists("Feld2") Then
- Set Marke2 = ActiveDocument.Bookmarks("Feld2").Range
- Set Marke3 = ActiveDocument.Bookmarks("Feld3").Range
- Set objCC = Marke2.ContentControls.Add(wdContentControlText)
- objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
- objCC.Title = TextBox1.Text
- ???
- 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
- Dim objCC As ContentControl
- If TextBox1.Visible = True Then
- If ActiveDocument.Bookmarks.Exists("Feld") Then
- Set Marke1 = ActiveDocument.Bookmarks("Feld").Range
- Marke1.Text = TextBox1.Text & ":"
- ActiveDocument.Bookmarks.Add Name:="Feld", Range:=Marke1
- End If
- If ActiveDocument.Bookmarks.Exists("Feld2") Then
- Set Marke2 = ActiveDocument.Bookmarks("Feld2").Range
- Set Marke3 = ActiveDocument.Bookmarks("Feld3").Range
- Set objCC = Marke2.ContentControls.Add(wdContentControlText)
- objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
- objCC.Title = TextBox1.Text
- 'ActiveDocument.Bookmarks("Feld2").Delete
- 'If ActiveDocument.ContentControls.Count > 3 Then
- 'ActiveDocument.Bookmarks("Feld3").Select
- Set myRange = ActiveDocument.ContentControls.Item(4).Range
- 'End If
- 'Dim WD As Word.Application
- 'WD = New Word.Application
- 'Dim wTable As Word.Table
- 'Set wTable = WD.ActiveDocument.Tables.Item(0)
- 'wTable.Cell(1, 1).Select()
- 'ActiveDocument.Tables(1).Rows(3).Cells(3).Select
- 'Selection.InsertAfter Text:="The end."
- 'Set Marke3 = objCC.Range
- 'Set Marke2 = ActiveDocument.objCC(TextBox1.Text).Range
- 'Muss noch überarbeitet werden!
- 'Selection.Words.Last.Next.Select
- 'ActiveDocument.Bookmarks("Feld2").Range.Characters.Last.Select
- 'Selection.Collapse wdCollapseStart
- 'Selection.TypeText "Material below is confidential."
- 'Set oContentControl = SelectedContentControl
- 'Set oContentControl = ActiveDocument.ContentControls(1).Range
- 'Set oContentControl = objCC.Range
- 'oContentControl.Collapse Direction:=wdCollapseStart
- ActiveDocument.Bookmarks.Add Name:="Feld2", Range:=myRange
- End If
- End If