如何使文本变红然后变黑?
How to make text red and then black again?
Sub MakeTextRed()
'
' MakeTextRed Macro
'
'
With Selection.Font
.Name = "+Body"
.Size = 16
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorRed
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.SizeBi = 16
.NameBi = "+Body CS"
.BoldBi = False
.ItalicBi = False
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
End Sub
快捷键是Shift+Alt+R
我想让它先将文本设为红色,然后如果我再次按相同的快捷方式,则将文本设为黑色。
我不了解 VBA。请提供逻辑或算法。
With Selection.Font
If .Color = wdColorRed then
.Color = wdColorBlack
else
.Color = wdColorRed
end if
End With
Sub toggleColor()
With Selection.Font
.Color = -wdColorRed * (.Color <> wdColorRed)
End With
End Sub
如果颜色不是红色,则 (.Color <> wdColorRed)
= -1(整数为真)且结果 = wdColorRed。否则 (.Color <> wdColorRed)
= 0(整数为假)且结果 = 0 (wdColorBlack)
Sub MakeTextRed()
'
' MakeTextRed Macro
'
'
With Selection.Font
.Name = "+Body"
.Size = 16
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorRed
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.SizeBi = 16
.NameBi = "+Body CS"
.BoldBi = False
.ItalicBi = False
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
End Sub
快捷键是Shift+Alt+R
我想让它先将文本设为红色,然后如果我再次按相同的快捷方式,则将文本设为黑色。
我不了解 VBA。请提供逻辑或算法。
With Selection.Font
If .Color = wdColorRed then
.Color = wdColorBlack
else
.Color = wdColorRed
end if
End With
Sub toggleColor()
With Selection.Font
.Color = -wdColorRed * (.Color <> wdColorRed)
End With
End Sub
如果颜色不是红色,则 (.Color <> wdColorRed)
= -1(整数为真)且结果 = wdColorRed。否则 (.Color <> wdColorRed)
= 0(整数为假)且结果 = 0 (wdColorBlack)