1

我正在尝试使用 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
4

1 回答 1

0

从访问中运行单词宏时,我遇到了完全相同的问题。(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

工作正常。和看起来一样愚蠢!

于 2013-07-18T15:52:52.310 回答