【问题标题】:InlineShape.Width not working on first runInlineShape.Width 在第一次运行时不起作用
【发布时间】:2012-12-28 18:40:26
【问题描述】:

我正在尝试使用 VBA 调整 Word 文档中的图片大小。该代码工作正常,但仅在第二次运行时。如果您打断它然后单步执行它,它也可以工作。有人可以评论我所缺少的吗?

Documents.Open FileName:=vDirectory & "\" & vFile

Dim objPic As InlineShape
For Each objPic In ActiveDocument.InlineShapes

If objPic.Width > CentimetersToPoints(16.51) Then
    With objPic
        .Width = CentimetersToPoints(16.51)
    End With
End If

Next objPic

【问题讨论】:

  • 这段代码在我的测试文档中运行良好。如果这仍然是个问题,您需要提供更多信息。

标签: vba image ms-word width


【解决方案1】:

我在从 access 运行 word 宏时遇到了完全相同的问题。 (Word也出现过错误)

我终于把我的代码改成了:

Dim objWord as object
Dim pic as InlineShape
Set objWord = CreateObject("Word.Application")    
With objWord.ActiveDocument
    For Each pic In .InlineShapes
        If pic.Width > 450 Then
            pic.Width = 450
        End If
    Next
End With

收件人:

Dim objWord as object
Dim pic as InlineShape
Set objWord = CreateObject("Word.Application")    
With objWord.ActiveDocument
    For Each pic In .InlineShapes
        If pic.Width > 450 Then
            pic.Width = 450
        End If
    Next
    For Each pic In .InlineShapes
        If pic.Width > 450 Then
            pic.Width = 450
        End If
    Next
End With

工作正常。看起来很愚蠢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多