将图片样式应用于word文档中的所有图片

时间:2016-07-11 11:17:40

标签: vba ms-word ms-office word-vba

是否有一种简单的方法可以主动或回溯地将'图片样式'应用于存储在word文档中的所有图像?

我想将“中心阴影矩形”图片样式应用于我添加到文档中的所有图像,而不是逐个更改它们。

2 个答案:

答案 0 :(得分:1)

图片样式概念仅存在于UI级别。要将其应用于图像,您必须在UI中检查样式的属性并使用VBA逐个应用它们:

Sub FormatPictures()

    Dim oInlineShape As inlineShape
    For Each oInlineShape In ActiveDocument.InlineShapes
        ApplyPictureStyleToInlineShape oInlineShape
    Next

    Dim oShape As Shape
    For Each shape In ActiveDocument.Shapes
        ApplyPictureStyleToShape oShape
    Next


End Sub

Sub ApplyPictureStyleToInlineShape(shape As inlineShape)

    ' borders
    shape.Borders.Enable = False

    ' fill
    shape.Fill.Visible = msoFalse

    ' line
    shape.Line.Visible = msoFalse

    ' shadow
    shape.Shadow.Style = msoShadowStyleOuterShadow
    shape.Shadow.Type = msoShadow21
    shape.Shadow.ForeColor = WdColor.wdColorBlack

    shape.Shadow.Transparency = 0.3
    shape.Shadow.Size = 100
    shape.Shadow.Blur = 15
    shape.Shadow.OffsetX = 0
    shape.Shadow.OffsetY = 0

    ' reflection
    shape.Reflection.Type = msoReflectionTypeNone

    ' glow
    shape.Glow.Radius = 0
    shape.SoftEdge.Radius = 0

End Sub

Sub ApplyPictureStyleToShape(shape As shape)

    ' fill
    shape.Fill.Visible = msoFalse

    ' line
    shape.Line.Visible = msoFalse

    ' shadow
    shape.Shadow.Style = msoShadowStyleOuterShadow
    shape.Shadow.Type = msoShadow21
    shape.Shadow.ForeColor = WdColor.wdColorBlack

    shape.Shadow.Transparency = 0.3
    shape.Shadow.Size = 100
    shape.Shadow.Blur = 15
    shape.Shadow.OffsetX = 0
    shape.Shadow.OffsetY = 0

    ' reflection
    shape.Reflection.Type = msoReflectionTypeNone

    ' glow
    shape.Glow.Radius = 0
    shape.SoftEdge.Radius = 0

End Sub

答案 1 :(得分:0)

刚刚受到你们(以及其他人的启发,所以感谢所有!),并制作了我自己的宏来格式化选定的粘贴图片,其中单边框(0.75 pt宽度)和简单的阴影偏移3 pts ... < / p>

我将该宏分配给一个图标,瞧!

粘贴图像后(大部分都是系统程序和文档的屏幕截图)。

在Word 2010中运行良好。 我没有测试过其他版本......

Sub FormatPictureWithLineAndShadow()
Dim oInlineShp As InlineShape
For Each oInlineShp In Selection.InlineShapes
    With oInlineShp
    'Line border
        With .Borders(wdBorderLeft)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth075pt
            .Color = wdColorAutomatic
        End With
        With .Borders(wdBorderRight)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth075pt
            .Color = wdColorAutomatic
        End With
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth075pt
            .Color = wdColorAutomatic
        End With
        With .Borders(wdBorderBottom)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth075pt
            .Color = wdColorAutomatic
        End With
        ' shadow
            .Shadow.Style = msoShadowStyleOuterShadow
            .Shadow.Type = msoShadow21
            .Shadow.ForeColor = WdColor.wdColorBlack
            .Shadow.Transparency = 0.6
            .Shadow.Size = 100
            .Shadow.Blur = 5
            .Shadow.OffsetX = 3
            .Shadow.OffsetY = 3
            ' reflection
            .Reflection.Type = msoReflectionTypeNone
            ' glow
            .Glow.Radius = 0
            .SoftEdge.Radius = 0
End With
    Next
End Sub