【问题标题】:How to remove a border from an inline shape如何从内联形状中删除边框
【发布时间】:2019-03-28 22:16:56
【问题描述】:

我在 Word 2010 上使用 VBA。

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

Mimic word borders and shading option "apply to:" (text) with vba on an inline shape

代码如下:

子 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

结束子

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

谢谢。

【问题讨论】:

  • 试试.Borders.Enable = False?

标签: vba ms-word


【解决方案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

上述方法会删除borders,但不会删除lines。要删除行,试试这个:

With rngShape.Line
    .Visible = msoFalse
End With

【讨论】:

  • 谢谢,但我已经尝试过了,但它也不起作用(虽然听起来应该) - 我仍然在图片周围留下一条以前不存在的小线我应用了边框。
  • 奇怪的是,如果您在 Word 2010 的兼容模式下对 .doc 文件执行此操作 - 它可以工作!
  • @DebS 查看修订版。您应该可以使用rngShape.Line.Visible = msoFalse 删除该行。
  • 谢谢它的工作 - 我现在已经更改了我的代码以添加“线条”并删除“线条”而不是边框​​,并且一切似乎都在工作:-)
  • 不客气!罪魁祸首是添加边框会自动导致添加一条线。您可以添加边框,只需记住删除边框和线条,或者,就像您正在做的那样,只需使用线条而不是边框​​。干杯!
【解决方案2】:

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

我不喜欢使用大多数其他人列出的Borders 方法来为InlineShape 添加边框,感谢大卫在这里的回答,我了解到您可以像您一样使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多