2013-04-16 153 views
0

字樣的圖片,當我使用Word宏內所有圖像縮小到9.3釐米此功能:VBA POWERPOINT:收縮從PowerPoint

Sub ShrinkWordImages() 
Dim iShp As InlineShape 

For Each iShp In ActiveDocument.InlineShapes 
    iShp.LockAspectRatio = msoTrue 
    iShp.Width = CentimetersToPoints(9.3) 
Next iShp 

End Sub 

但是,當我嘗試從一個PowerPoint宏內運行,參考一個單詞文檔(所有參考文獻都適當),單詞文檔中的圖像就會消失。 從PowerPoint我用這個,而其唯一的區別:

For Each iShp In wrdDoc.InlineShapes 

凡wrdDoc已經正確地申報和設置。

宏完成後,Powerpoint也崩潰。 我試着改變iShp爲變體,但沒有幫助。

編輯:因此,我已經確定CentimetersToPoints(9.3)在PowerPoint中返回0,而在Word中則爲263或更多。現在看看。

回答

1

在PowerPoint中沒有什麼像CentimetersToPoint,您可以在您的情況下調用它。您需要引用您的Word對象變量以獲取維度。也許是這樣的:

Sub CentimetersTo_Word() 

    Dim WRD As Object 
    Set WRD = CreateObject("Word.Application") 

    Debug.Print WRD.centimeterstopoints(10) 

End Sub 

因此,只需添加您的Word應用程序引用之前CentimetersToPoint

+0

+ 1解釋爲什麼它沒有工作。 :) –

0

只是做了我自己的方法...它的工作。

Function CmToPt(pt As Single) As Single 
CmToPt = pt * 28.35 
End Function 

不知道爲什麼正常的工作沒有工作,但這沒有把戲。