Sub TestFunction()
'This is for testing the following function
Dim strComment As String
Debug.Print Test_Heading_1_Attributes("[i]Enter_your_source_filename/path here[/i]", strComment), strComment
End Sub
Function Test_Heading_1_Attributes(DocumentName As String, FailComments As String) As Boolean
On Error GoTo Test_Heading_1_Attributes_Error
Const DefaultFontColor As Long = -16777216
'Declarations for the OLE object
Dim MyWordApplication As Object
Dim MyWordDocument As Object 'Document
Dim MyWordParagraph As Object 'Paragraph
Dim MyWordRange As Object 'Range
Dim MyWordFont As Object 'Font
'Get the word container
Set MyWordApplication = CreateObject("Word.Application")
'Open the document feed to the function
Set MyWordDocument = MyWordApplication.Documents.Open(DocumentName, , True)
'Get the rest of the objects
Set MyWordParagraph = MyWordDocument.Paragraphs(1) 'First paragraph
Set MyWordRange = MyWordParagraph.Range
Set MyWordFont = MyWordRange.Font
With MyWordFont
'Test for Arial font face
If .Name = "Arial" Then
Test_Heading_1_Attributes = True
ElseIf .Name = "" Then
Test_Heading_1_Attributes = False
FailComments = FailComments & "Font Name is mixed. "
End If
'Test for font size 16
If .Size = 16 Then
Test_Heading_1_Attributes = Test_Heading_1_Attributes And True
ElseIf .Size = 9999999 Then
Test_Heading_1_Attributes = False
FailComments = FailComments & "Font Size is mixed. "
End If
'Test for font color Blue
If .Color = vbBlue Then
Test_Heading_1_Attributes = Test_Heading_1_Attributes And True
ElseIf .Color = DefaultFontColor Then
Test_Heading_1_Attributes = False
FailComments = FailComments & "Font color is set to default. "
ElseIf .Color = 9999999 Then
Test_Heading_1_Attributes = False
FailComments = FailComments & "Font color is mixed. "
End If
End With
Clean_Up:
Set MyWordFont = Nothing
Set MyWordRange = Nothing
Set MyWordParagraph = Nothing
MyWordDocument.Close
Set MyWordDocument = Nothing
MyWordApplication.Quit
Set MyWordApplication = Nothing
Exit Function
Test_Heading_1_Attributes_Error:
Debug.Print Err.Number, Err.Description
Resume Clean_Up
End Function