内联形状的两倍大小

时间:2018-12-06 09:15:57

标签: vba ms-word

编码新手,如果有人可以帮助我,将非常感谢您的帮助。该代码应该在没有内嵌形状时以及在存在内嵌形状时输出消息...它将内嵌形状的比例(大小* 2)加倍。

我遇到了一些问题...代码没有注意到文档中有内嵌形状...也没有改变内嵌形状的长宽比/大小。

谢谢!

Sub InlineShapesModify ()
Dim RangeShape As word.Range
Set RangeShape = ActiveDocument.Content
Dim ShapeCount As Integer

ShapeCount = 0
With RangeShape.Find
    .Forward = True
    .Execute
    Do While .Found
        ShapeCount = ShapeCount + 1
        RangeShape.Collapse word.WdCollapseDirection.wdCollapseEnd
        .Execute
    Loop
End With

If (ShapeCount = 0) Then
    MsgBox ("No images to modify")
    Exit Sub
ElseIf (ShapeCount > 0) Then
Do While (ShapeCount > 0)
    ActiveDocument.InlineShapes(i).Height = _
    ActiveDocument.InlineShapes(i).Height * 2
    Loop
End If

End Sub

1 个答案:

答案 0 :(得分:1)

假设您要做的就是将所有内嵌形状的高度和宽度加倍,如果在文档中没有内嵌形状,则显示一条消息,这应该起作用:

Sub ilshapes()
    Dim h As Long, w As Long, rng As Range, sh As InlineShape

    Set rng = ActiveDocument.Content

    If rng.InlineShapes.Count = 0 Then
        MsgBox "No images to modify."
        Exit Sub
    End If

    For Each sh In ActiveDocument.InlineShapes
        h = sh.Height
        w = sh.Width

        sh.Height = 2 * h
        sh.Height = 2 * w
    Next sh

    MsgBox rng.InlineShapes.Count & " images modified."
End Sub