首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从内联形状中删除边框

如何从内联形状中删除边框
EN

Stack Overflow用户
提问于 2013-05-16 21:29:15
回答 2查看 7K关注 0票数 1

我正在用VBA编写Word 2010。

我有一些代码来添加边框到一个内联图形,这是工作正常,但我需要能够删除边框,这似乎不工作。我已经在这个网站上搜索过了,除了这个之外,我找不到任何更接近的东西:

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

代码如下:

子TestAddBorders()

代码语言:javascript
复制
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()

代码语言:javascript
复制
Dim rngShape As InlineShape

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

结束子对象

我总是看到一张周围有灰色边框的图片(inlineshape)。使用“图片工具”>“格式”选项卡上的“图片边框>无轮廓”可以删除它,但我无法在VBA中找到任何方法来删除它。wdLineStyleNone似乎不工作,我看不到颜色=“无”或线宽=“无”的选项

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-16 21:54:56

来自MSDN:

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

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

这将在应用边框时将其删除:

代码语言:javascript
复制
Sub TestRemoveBorders()

Dim rngShape As InlineShape

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

        .Enable = False
    End With
Next rngShape
End Sub

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

代码语言:javascript
复制
With rngShape.Line
    .Visible = msoFalse
End With
票数 1
EN

Stack Overflow用户

发布于 2019-03-28 22:16:56

David的答案是正确的,但我想为后来偶然发现这一点的人补充一下。

我不喜欢使用我看到的大多数人列出的Borders方法来向InlineShape添加边框,多亏了David在这里的回答,我了解到您可以像使用普通Shape一样使用Line成员!

我知道,对于那些没有自己设置边界的人来说,这可能不能准确地回答这个问题,但在我个人的情况下,它是有帮助的。考虑到这一点,下面是添加和删除形状边框的方法的修订版本。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16588789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档