我在VBA上使用Word 2010。
我有一些代码来添加边框到一个正常工作的inlines形状,但我需要能够删除边框,这似乎没有工作。我搜索了这个网站,找不到与此相近的任何内容:
Mimic word borders and shading option "apply to:" (text) with vba on an inline shape
代码如下:
Sub 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
结束子
Sub 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”的选项
谢谢。
来自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
大卫的回答是正确的,但我想为那些后来偶然发现这一点的人添加它。
我不想使用Borders
方法,我看到大多数其他人列表为InlineShape
添加边框,并且由于大卫的回答,我知道你可以像正常的Line
s一样使用Shape
成员!
我知道这可能不能完全回答那些不是自己设置边界的人的问题,但在我个人的情况下,这是有帮助的。考虑到这一点,以下是从形状添加和删除边框的方法的修订版本。
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