Microsoft Office Forum [ www.Office-Fragen.de ] >> READONLY <<
Microsoft Office 2003-2019 => Word => Thema gestartet von: TheaAmanda am September 10, 2012, 10:02:15 Vormittag
-
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.
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 objCC = Marke2.ContentControls.Add(wdContentControlText)
objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
objCC.Title = TextBox1.Text
ActiveDocument.Bookmarks.Add Name:="Feld2", Range:=Marke2
End If
End If
-
ich wäre wirklich über jede hilfe dankbar (bitte bitte bitte) - bei der range verlegung steh ich einfach aufm schlauch.
hier meine gehversuche:
Dim objCC As ContentControl
Dim oContentControl As Range
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 objCC = Marke2.ContentControls.Add(wdContentControlText)
objCC.SetPlaceholderText Text:="[" & TextBox1.Text & "]"
objCC.Title = TextBox1.Text
'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:=Marke2
End If
End If
-
Hallo TheaAmanda...
bin jetzt nicht so fit in Word VBA, das Range Objekt ist, laut Objektkatalog schreibgeschützt.
Es sind aber z.B. Eigenschaften, wie Text usw. vorhanden.
Könntest vielleicht den Objektkatalog durchstöbern (VBA Editor -> F2) und angefangen bei
ContentControls zu ContentControl bishin zu Range die Eigenschaften und Methoden
anschauen. F1 auf einen Eintrag liefert die MS VBA Hilfe.
Gruß