我正在用VBA编写Word 2010。
我有一些代码来添加边框到一个内联图形,这是工作正常,但我需要能够删除边框,这似乎不工作。我已经在这个网站上搜索过了,除了这个之外,我找不到任何更接近的东西:
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结束子对象
我总是看到一张周围有灰色边框的图片(inlineshape)。使用“图片工具”>“格式”选项卡上的“图片边框>无轮廓”可以删除它,但我无法在VBA中找到任何方法来删除它。wdLineStyleNone似乎不工作,我看不到颜色=“无”或线宽=“无”的选项
谢谢。
发布于 2013-05-16 21:54:56
来自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发布于 2019-03-28 22:16:56
David的答案是正确的,但我想为后来偶然发现这一点的人补充一下。
我不喜欢使用我看到的大多数人列出的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 Subhttps://stackoverflow.com/questions/16588789
复制相似问题