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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16588789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:09:04  来源:igfitidea点击:

How to remove a border from an inline shape

vbams-wordword-vba

提问by DebS

I am working in VBA on Word 2010.

我在 Word 2010 上使用 VBA。

I have some code to add borders to an inlineshape which is working ok, but I need to be able to remove the border and that doesn't seem to be working. I've searched through this site and can't find anything close apart from this:

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

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

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

Code is a follows:

代码如下:

Sub TestAddBorders()

子测试AddBorders()

Dim rngShape As InlineShape

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

End Sub

结束子

Sub TestRemoveBorders()

子测试RemoveBorders()

Dim rngShape As InlineShape

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

End Sub

结束子

I am always left with a picture (inlineshape) that has a greyish border around it. Using "Picture Border > No Outline" on the Picture Tools > Format Tab removes it, but I can' find any way to do it in VBA. The wdLineStyleNone just doesn't seem to work and I can't see an option for colour = "none", or linewidth = "none"

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

Thank you.

谢谢你。

采纳答案by David Zemens

From MSDN:

来自 MSDN:

To remove all the borders from an object, set the Enable property to False.

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

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

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

This will remove the borders as you applied them:

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

Sub TestRemoveBorders()

Dim rngShape As InlineShape

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

        .Enable = False
    End With
Next rngShape
End Sub

The above method removes bordersbut not lines. To remove lines, try this:

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

With rngShape.Line
    .Visible = msoFalse
End With

回答by Marcucciboy2

David's answer is correct, but I wanted to add to it for anyone who stumbles upon this later.

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

I prefer not to use the Bordersmethod that I see most other people list to add a border to an InlineShape, and thanks to David's answer here I learned that you can just use the Linemember like you can with normal Shapes!

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

I'm aware that this might not exactly answer the question for those of you who are not also setting the border yourself, but in my personal case it was helpful. With that in mind, here are the revised versions of methods to Add and Remove the borders from 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