【发布时间】:2020-12-04 00:12:29
【问题描述】:
尽管给了我一个运行时错误 451“Property Let Procedure Not Defined And Property Get Procedure Did Not Return Object”,但以下代码成功运行。
调试器将With oCC.Range.Style("Placeholder Text").Font 标记为罪魁祸首。
我需要对占位符文本应用一种样式,以便在输入或删除值时它不会重置。
缺少什么?
Dim oTable As Table
Dim ocell As Cell
Dim oCC As ContentControl
Dim oNewRow As Row
Set oTable = ActiveDocument.Tables(1)
Set oNewRow = oTable.Rows.Add
Set ocell = oNewRow.Cells(1)
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlRichText, ocell.Range)
With oCC
.DefaultTextStyle = "Style1"
.Tag = "Test1"
.Setplaceholdertext , , "test1"
If oCC.ShowingPlaceholderText Then
With oCC.Range.Style("Placeholder Text").Font
.Name = "Arial"
.Size = 8
.ColorIndex = wdRed
.Italic = True
End With
End If
End With
【问题讨论】:
-
您的意思是使用
With oCC.Range.Font吗?一个猜测。 -
不,我需要对占位符文本应用样式,这样它就不会重置为默认样式
-
With ActiveDocument.Styles("Placeholder Text").Font有效,但它设置了整个文档的样式,而不仅仅是一个单元格。我想在整个文档中使用不同的占位符文本样式 -
您要么必须为 oCC.Range 应用新样式,要么设置 oCC 范围的字体属性。