使用VBA宏更改插入行颜色

时间:2015-05-13 02:13:19

标签: vba word-vba word-2010

下面的代码是在Microsoft Word 97-2003中创建的(不是我,并保存为* .dotm),当默认情况下"插入形状/行"是黑色的。用作具有特定封面,标题,大纲样式等的过程模板。当* .doc文件保存到* .docx时," SignoffLine"宏被激活,插入的线条颜色为蓝色(插入形状/线条的MS Word 2010默认值?)。

我可以更改每个文档的默认颜色,我可以通过Normal.dotm更改它,但是想要编辑下面的宏,这样插入的行总是黑色的。

Sub SignoffLine()
    On Error GoTo endthis
    i = Selection.Information(wdVerticalPositionRelativeToPage)
    Set oFFline = ActiveDocument.Shapes.AddLine(554, i + 12, 524, i + 12).Line

    With oFFline.Line
        .Weight = 0.75
    End With
        oFFline.Name = "hline" & idi
        idi = idi + 1
    endthis:
End Sub

1 个答案:

答案 0 :(得分:0)

这很简单......您需要将oFFline对象定义为Shape,然后将其属性设置如下:

Sub SignoffLine()
    Dim oFFline As Shape
    Dim i As Integer

    On Error GoTo endthis

    i = Selection.Information(wdVerticalPositionRelativeToPage)
    Set oFFline = ActiveDocument.Shapes.AddLine(554, i + 12, 524, i + 12)

    With oFFline.Line
        .Weight = 0.75
        'set black color 
        .ForeColor.RGB = RGB(0, 0, 0)
    End With
    oFFline.Name = "hline" & idi
    idi = idi + 1

    endthis:
    Set oFFline = Nothing
End Sub

有关详细信息,请参阅:Shape Object (Word)RGB