热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用VBA宏更改插入行颜色-ChangeinsertlinecolorwithVBAmacro

Codebelowwascreated(notbyme,andsavedas*.dotm)inMicrosoftWord97-2003,whendefaultins

Code below was created (not by me, and saved as *.dotm) in Microsoft Word 97-2003, when default "insert shape/line" was black. Used as procedure template with specific cover page, header, outline style, etc. When the *.doc files are saved to *.docx, and the "SignoffLine" macro is activated, the inserted line's color is blue (MS Word 2010 default for Insert Shape/Line?).

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

I can change the default color per document, and I can change it via Normal.dotm, but want to edit the macro below so inserted line is always black.

我可以更改每个文档的默认颜色,我可以通过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 个解决方案

#1


It's quite simple... You need to define oFFline object as a Shape and then to set its properties as follow:

这很简单......您需要将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

For further information, please see: Shape Object (Word) and RGB

有关详细信息,请参阅:形状对象(Word)和RGB


推荐阅读
author-avatar
A丶Iice-fjl
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有