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

Vba 如何从内联形状中删除边框,vba,ms-word,Vba,Ms Word,我在VBA的Word 2010上工作 我有一些代码添加边界到一个inlineshape,这是正常工作,但我需要能够删除边界,这似乎不工作。我已搜索过此网站,但找不到任何与此相关的内容: 代码如下: 子测试边界() 端接头 子TestRemoveBorders() 端接头 我总是留下一张周围有灰色边框的图片(inlineshape)。使用“图片工具>格式”选项卡上的“图片边框>无轮廓”可以删除它,但我找不到任何方法在VBA中实现它。wdLineStyleNone似乎不起作用,我看不到color=

我在VBA的Word 2010上工作

我有一些代码添加边界到一个inlineshape,这是正常工作,但我需要能够删除边界,这似乎不工作。我已搜索过此网站,但找不到任何与此相关的内容:

代码如下:

子测试边界()

端接头

子TestRemoveBorders()

端接头

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

谢谢。

来自MSDN:

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

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

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
从MSDN:

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

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

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

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

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

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

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

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

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

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

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

试试
.Borders.Enable=False
?试试
.Borders.Enable=False
?谢谢,但我试过了,它也不起作用(尽管听起来应该这样)-在我应用边框之前,我仍然会在图片周围留下一条不存在的小线条。奇怪的是,如果在Word 2010中以兼容模式在.doc文件上执行此操作,它会工作@DebS见修订版。您应该能够使用
rngShape.Line.Visible=msoFalse
删除该行。谢谢您,它可以工作-我现在已将代码更改为添加“行”并删除“行”,而不是边框,所有操作似乎都可以工作:-)欢迎您!罪魁祸首是添加边框也会自动导致添加线条。您可以添加边框,只需记住删除边框和线条,或者,就像您正在做的那样,只需使用线条而不是边框。干杯谢谢,但我试过了,但也不起作用(尽管听起来应该如此)-我仍然在图片周围留下了一条在我应用边框之前不存在的小线条。奇怪的是,如果你在Word 2010中以兼容模式在.doc文件上这样做,它就起作用了@DebS见修订版。您应该能够使用
rngShape.Line.Visible=msoFalse
删除该行。谢谢您,它可以工作-我现在已将代码更改为添加“行”并删除“行”,而不是边框,所有操作似乎都可以工作:-)欢迎您!罪魁祸首是添加边框也会自动导致添加线条。您可以添加边框,只需记住删除边框和线条,或者,就像您正在做的那样,只需使用线条而不是边框。干杯