我有一个插入文本的宏。到目前为止它运行良好,但是...现在对于某些文档,当它应用颜色时会出现错误445。 下面是代码:VBA Word:Font.TextColor和Font.ColorIndex之间的区别?
'Some code before that insert a first page with a different section and writes into the header
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.TypeParagraph
With Selection.Font
.Name = "Calibri"
.Size = 14
.Bold = True
.Italic = False
.TextColor = RGB(68, 114, 196)
End With
With Selection.ParagraphFormat
.Alignment = wdAlignParagraphCenter
.SpaceAfter = 6
End With
Selection.TypeText Text:="eReference file for work order: "
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="workorder"
Selection.TypeParagraph
我已经通知,如果我改变 “Selection.Font.TextColor = RGB(68,114,196)” 和由替换为 “Selection.Font.ColorIndex = wdDarkBlue” , 有用。因此我的问题是:两者有什么区别?为什么有一些“Textcolor”不起作用的文档?
谢谢!
。TextColor是只读的,所以你不能将它设置为你想要的颜色。 – gizlmo
它的工作原理?你的意思是设置'Font.ColorIndex = RGB(68,114,196)'将颜色设置为RGB(64,114,196)?或者仅仅是它不会崩溃?因为鉴于'WdColorIndex'枚举的性质,我非常怀疑将它分配给RGB值会给你你提供的颜色。我可能错了 - 虽然我不太熟悉Word对象模型。 –
@ Mat'sMug我的意思是,如果我使用'Selection.Font.ColorIndex = wdDarkBlue'例如,它将颜色设置为深蓝色。 – Pookye