You must hard code. If you
really want to know what the attributes are - for the style AND for the actual text - you have to explicitly check them. Here is a
partial list.
Code:
With Selection.Font
.Name = "Times New Roman"
.Size = 12
.Bold = False
.Italic = True
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
With Selection.ParagraphFormat
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
So, again, say your style did NOT have a shadow border (you never set it), then it is not as if there is an empty, or Null, space/attribute for that. It is explicitly set as False. EVERY attribute is set for EVERY paragraph. There are no Null attributes.
So say, the user made it a shadow border. There is NO WAY to know that (by code anyway) until you actually check.
Are you following? If you need to know if ANY attribute (any at all) is different from the style, you must actually check it. Again, this is why I reset any found instances of a style TO be precisely that style. This makes all the attributes match the style again.
I will ask again. WHAT do you want to really happen? OK, so you go through the document and highlight changed format. OK, you display a message telling the user that changed format has been found, and it is now highlighted.
The user goes....yeah, so what...and does nothing. Is this what you want? If the character style is significant, if it is supposed to be what it is supposed to be...then why are you asking? Why not just change to what it is suppsed to be?
- some process that we run on the files fail if character styles have been altered.
If this is true...don't ask, don't mention it...just change it to the appropriate style.
Code:
Sub Checkxref()
Dim myRange As Word.Range
Dim aWord
Set myRange = ActiveDocument.Range
For Each aWord In myRange.Words
If aWord.Style = "xref" Then
If aWord.Font.Size <> 16 _
Or aWord.Font.Color <> wdBlack _
Or aWord.Font <> "Arial" Then
aWord.Select
Selection.Range.HighlightColorIndex = wdYellow
End If
End If
Next aWord
Set myRange = Nothing
Msgbox "Manually formatted character styles have been found, these have been highlighted"
End Sub
There you go. That will go through the document checking for character style "xref", check found instances of xref for specifically Font.Size NOT being 16; Font.Color NOT being black; and Font NOT being Arial.
If you want to check any other attributes you MUST explicitly add them, one by one. There is NO available summary description of style attributes.
IMHO you need to assess purposes. IMHO if a character style has been created then it should have meaning. ANY manual format should revert to the style. in which my simple first code will do it.
Gerry