1

我在 Word 2010 上使用 VBA。

我有一些代码可以将边框添加到运行正常的内联形状,但我需要能够删除边框,但这似乎不起作用。我已经搜索了这个网站,除了这个之外找不到任何东西:

在线形状上使用 vba 模拟单词边框和阴影选项“适用于:”(文本)

代码如下:

子 TestAddBorders()

Dim rngShape As InlineShape

For Each rngShape In ActiveDocument.InlineShapes
    With rngShape.Range.Borders
        .OutsideLineStyle = wdLineStyleSingle
        .OutsideColorIndex = wdPink
        .OutsideLineWidth = wdLineWidth300pt
    End With
Next rngShape

结束子

子 TestRemoveBorders()

Dim rngShape As InlineShape

For Each rngShape In ActiveDocument.InlineShapes
    With rngShape.Range.Borders
        .OutsideLineStyle = wdLineStyleNone
    End With
Next rngShape

结束子

我总是留下一张带有灰色边框的图片(inlineshape)。在“图片工具”>“格式”选项卡上使用“图片边框>无轮廓”将其删除,但我无法在 VBA 中找到任何方法。wdLineStyleNone 似乎不起作用,我看不到 color = "none" 或 linewidth = "none" 的选项

谢谢你。

4

2 回答 2

1

来自 MSDN:

要删除对象的所有边框,请将 Enable 属性设置为 False。

http://msdn.microsoft.com/en-us/library/office/ff196058.aspx

这将在您应用它们时删除边框:

Sub TestRemoveBorders()

Dim rngShape As InlineShape

For Each rngShape In ActiveDocument.InlineShapes
    With rngShape.Range.Borders

        .Enable = False
    End With
Next rngShape
End Sub

上述方法删除边框但不删除线。要删除行,请尝试以下操作:

With rngShape.Line
    .Visible = msoFalse
End With
于 2013-05-16T13:54:55.630 回答
0

大卫的回答是正确的,但我想为以后偶然发现这一点的人补充一下。

我不喜欢使用Borders我看到大多数其他人列出的方法来为 an 添加边框InlineShape,并且感谢 David 在这里的回答,我了解到您可以Line像使用普通Shapes 一样使用该成员!

我知道这可能无法完全回答那些自己也没有设置边界的人的问题,但就我个人而言,这很有帮助。考虑到这一点,这里是从形状中添加和删除边框的方法的修订版本。

Option Explicit

Sub PicturesAll_Borders_Show()

    'for pictures which are "In Line with Text"
    Dim inShp As InlineShape
    For Each inShp In ActiveDocument.InlineShapes
        If inShp.Type = wdInlineShapePicture Then
            With inShp.Line
                .Visible = True
                .Style = msoLineSingle
                .Weight = 1
                .ForeColor.RGB = RGB(0, 0, 0)
            End With
        End If
    Next inShp

    'for pictures which are "With Text Wrapping"
    Dim shp As Shape
    For Each shp In ActiveDocument.Shapes
        If shp.Type = msoPicture Then
            With shp.Line
                .Visible = True
                .Style = msoLineSingle
                .Weight = 1
                .ForeColor.RGB = RGB(0, 0, 0)
            End With
        End If
    Next shp

End Sub


Sub PicturesAll_Borders_Hide()

    'for pictures which are "In Line with Text"
    Dim inShp As InlineShape
    For Each inShp In ActiveDocument.InlineShapes
        If inShp.Type = wdInlineShapePicture Then inShp.Line.Visible = False
    Next inShp

    'for pictures which are "With Text Wrapping"
    Dim shp As Shape
    For Each shp In ActiveDocument.Shapes
        If shp.Type = msoPicture Then shp.Line.Visible = False
    Next shp

End Sub
于 2019-03-28T14:16:56.433 回答