2013-01-14 56 views
1

我正在尝试使用VBA在Word文档中调整图片大小。该代码工作正常,但只有第二次运行。如果你打断它,然后逐步完成,它也可以工作。有人可以评论我错过了什么吗?InlineShape.Width第一次运行不起作用

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 
+0

此代码可以正常使用我的测试文档。如果这仍然是一个问题,您需要提供更多信息。 – ForEachLoop

回答

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 

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

相关问题