在 Word Doc 中的图像周围添加蓝色边框的 VBA 代码

问题描述 投票:0回答:1

我有一个word文档,里面有PPT幻灯片图像。我需要所有 PPT 图像,但只有 PPT 图像周围有蓝色边框。幻灯片图像的尺寸为 1.39 x 1.85,比所有小图标图像都大,因此我尝试使用该属性仅使幻灯片图像带有边框。我可以手工完成,但每个文档有 70-90 张幻灯片图像。

这是我尝试过的代码:

Sub Borders()
Dim pic As Long, image As Long

With ActiveDocument.Range
For pic = 1 To .InlineShapes.Count
    With .InlineShapes(pic)
    If .Height = CentimetersToPoints(1.39) Then
    .Borders(pic).Color = RGB(20, 86, 162)
    .Borders(pic).LineWidth = wdLineWidth1pt
    End If
End With
Next pic
End With

End Sub
vba image ms-word border
1个回答
0
投票

这样的东西应该有效:

Sub Borders()
    Dim pic As Shape
    
    For Each pic In ThisDocument.Range.ShapeRange        'loop all shapes
        Debug.Print TypeName(pic)
        If pic.Height > CentimetersToPoints(1.39) Then   'check min size 
            With pic.Line                                'style the border
                .Visible = True
                .Style = msoLineSingle
                .Weight = 1
                .ForeColor.RGB = vbBlue
            End With
        End If
    Next pic
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.