2013-01-14 59 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 

工作正常。像看起來一樣愚蠢!

相關問題