Reputation: 349
The weight of the day yesterday, I tried to add this code so that it changes the highlight color of the text to the one shown in the picture. I found a lot of information on the Internet, but unfortunately, it does not work in the context of my code. What to do?) How to change the color of the text selection?
Option Explicit
Dim WA,WD,Sel ' Объявляем переменные
'Создаем объект¬–приложение Microsoft Word
Set WA=WScript.CreateObject("Word.Application")
' Можно было использовать конструкцию
' Set WA=CreateObject("Word.Application")
Set WD=WA.Documents.Add 'Создаем новый документ (объект Document)
WA.Visible=true ' Делаем Word видимым
Set Sel=WA.Selection 'Создаем объект Selection
Sel.Font.Size=14 'Устанавливаем размер шрифта
Sel.ParagraphFormat.Alignment=1 'Выравнивание по центру
Sel.Font.Bold=true 'Устанавливаем полужирный шрифт
Sel.TypeText "Понятие сценариев" & vbCrLf 'Печатаем строку текста
Sel.Font.Bold=false 'Отменяем полужирный шрифт
Sel.ParagraphFormat.Alignment=0 'Выравнивание по левому краю
'Печатаем строку текста
Sel.TypeText " Сценарий – это пакетный файл, позволяющий автоматизировать действия системного администратора."
Upvotes: 1
Views: 593
Reputation: 5031
You can use the HighlightColorIndex
property with one of the WdColorIndex constants:
WdColorIndex enumeration (Word)
With the code you provided, you would use Sel.Range.HighlightColorIndex = 10
I think, but you can experiment.
You can also use Sel.Range.Shading.BackgroundPatternColor
with the same constants or an RGB value directly.
Upvotes: 2