Word VBA教程:HTMLDivision对象

   
HTMLDivisions
HTMLDivision
多种对象

该对象代表可添加至 Web 文档的单独的 HTML 区域。HTMLDivision对象是HTMLDivisions集合的一个成员。

使用 HTMLDivision对象

使用HTMLDivisions(index) 可返回单独的 HTMLDivision对象,其中 index 引用文档中的 HTML 区域。使用Borders属性可设置 HTML 区域边框格式的属性。本示例设置活动文档中三个嵌套区域的格式。本示例假定该活动文档是一个 HTML 文档,其中具有至少三个区域。


Sub FormatHTMLDivisions()
    With ActiveDocument.HTMLDivisions(1)
        With .Borders(wdBorderLeft)
            .Color = wdColorRed
            .LineStyle = wdLineStyleSingle
        End With
        With .Borders(wdBorderTop)
            .Color = wdColorRed
            .LineStyle = wdLineStyleSingle
        End With
        With .HTMLDivisions(1)
            .LeftIndent = InchesToPoints(1)
            .RightIndent = InchesToPoints(1)
            With .Borders(wdBorderRight)
                .Color = wdColorBlue
                .LineStyle = wdLineStyleDouble
            End With
            End With
            With .Borders(wdBorderBottom)
                .Color = wdColorBlue
                .LineStyle = wdLineStyleDouble
            End With
            With .HTMLDivisions(1)
                .LeftIndent = InchesToPoints(1)
                .RightIndent = InchesToPoints(1)
                With .Borders(wdBorderLeft)
                    .Color = wdColorBlack
                    .LineStyle = wdLineStyleDot
                End With
                With .Borders(wdBorderTop)
                    .Color = wdColorBlack
                    .LineStyle = wdLineStyleDot
                End With
            End With
        End With
    End With
End Sub

HTML 区域可在多个 HTML 区域中嵌套。使用HTMLDivisionParent方法可访问当前 HTML 区域的 HTML 父区域。本示例设置活动文档中两个 HTML 区域的边框格式,本示例假定该活动文档是一个 HTML 文档,其中具有至少两个区域。


Sub FormatHTMLDivisions()
    With ActiveDocument.HTMLDivisions(1)
        With .HTMLDivisions(1)
            .LeftIndent = InchesToPoints(1)
            .RightIndent = InchesToPoints(1)
            With .Borders(wdBorderLeft)
                .Color = wdColorBlue
                .LineStyle = wdLineStyleDouble
            End With
            With .Borders(wdBorderRight)
                .Color = wdColorBlue
                .LineStyle = wdLineStyleDouble
            End With
            With .HTMLDivisionParent
                .LeftIndent = InchesToPoints(1)
                .RightIndent = InchesToPoints(1)
                With .Borders(wdBorderTop)
                    .Color = wdColorBlack
                    .LineStyle = wdLineStyleDot
                End With
                With .Borders(wdBorderBottom)
                    .Color = wdColorBlack
                    .LineStyle = wdLineStyleDot
                End With
            End With
        End With
    End With
End Sub

Word VBA教程

Word VBA参考教程:目录1 Word VBA参考教程:目录2
Word VBA参考教程:目录3 Word VBA参考教程:目录4
Word VBA参考教程:目录5 Word VBA参考教程:目录6
Word VBA参考教程:目录7 Word VBA参考教程:目录8
Word VBA参考教程:目录9 Word VBA参考教程:目录10
版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号