K
KWarner
Using VBA in Word 2007.
I'm trying to add a content control into a form. I can get the
formatting(Arial, 15) for the placeholder text set correctly unless the user
enters some text and then deletes that text so the placeholder text gets
re-shown. The placeholder text always goes back to the default formatting
(Calibri, 11).
This is a sample code that demonstrates this behavior. Can someone please
tell me where my thinking is wrong?
Sub test()
Dim text As String
text = "This is a test CC: "
Dim ccText As String
ccText = "enter the testCC text"
Dim cc As ContentControl
Selection.Range = text
Selection.WholeStory
Selection.Range.Font.Name = "Arial"
Selection.Range.Font.Size = 15
Selection.Collapse
Selection.EndKey unit:=wdLine
Set cc = Selection.Range.ContentControls.Add(wdContentControlText)
cc.SetPlaceholderText text:=ccText
cc.Title = ""
cc.Range.Select
Selection.MoveLeft unit:=wdCharacter, Count:=1
Selection.MoveRight unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Range.Font.Name = "Arial"
Selection.Range.Font.Size = 15
Selection.Range.Font.Bold = True
End Sub
Thanks,
Kevin
I'm trying to add a content control into a form. I can get the
formatting(Arial, 15) for the placeholder text set correctly unless the user
enters some text and then deletes that text so the placeholder text gets
re-shown. The placeholder text always goes back to the default formatting
(Calibri, 11).
This is a sample code that demonstrates this behavior. Can someone please
tell me where my thinking is wrong?
Sub test()
Dim text As String
text = "This is a test CC: "
Dim ccText As String
ccText = "enter the testCC text"
Dim cc As ContentControl
Selection.Range = text
Selection.WholeStory
Selection.Range.Font.Name = "Arial"
Selection.Range.Font.Size = 15
Selection.Collapse
Selection.EndKey unit:=wdLine
Set cc = Selection.Range.ContentControls.Add(wdContentControlText)
cc.SetPlaceholderText text:=ccText
cc.Title = ""
cc.Range.Select
Selection.MoveLeft unit:=wdCharacter, Count:=1
Selection.MoveRight unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Range.Font.Name = "Arial"
Selection.Range.Font.Size = 15
Selection.Range.Font.Bold = True
End Sub
Thanks,
Kevin