如何輕鬆調整PowerPoint投影片上的圖片大小?
你是否曾經在製作PowerPoint簡報時,因為圖片大小需要一張一張點選調整而感到困擾?如果你有這樣的經驗,那麼本文將為你介紹一個簡單而有效的方法來不用點選就可以調整投影片上的所有圖片大小。使用VBA調整投影片上的圖片大小
使用VBA可以幫助你以更快速和有效的方式處理PowerPoint簡報中的多個圖片,而不必手動一個一個地進行調整。下面是一個簡單的VBA程式碼,可用於在PowerPoint投影片中調整所有圖片的大小:
Sub AdjustImages()
Dim objPic As Shape
Dim sUserInput As String
Dim lValue As Long
Dim lValueCM As Single
'Prompt the user to select whether to adjust the height or width of the images
sUserInput = InputBox("Enter 'H' to adjust height or 'W' to adjust width")
'Prompt the user to enter the desired value in centimeters
lValue = InputBox("Enter the desired value in centimeters")
'Convert the value to points
lValueCM = lValue / 2.54 * 72
'Set the height or width of each picture on the active slide based on the user's input
For Each objPic In ActivePresentation.Slides(ActiveWindow.View.Slide.slideIndex).Shapes
If objPic.Type = msoPicture Then
If sUserInput = "H" Then
objPic.Height = lValueCM
objPic.LockAspectRatio = msoTrue
ElseIf sUserInput = "W" Then
objPic.Width = lValueCM
objPic.LockAspectRatio = msoTrue
End If
End If
Next objPic
End Sub
如何使用VBA程式碼來調整圖片大小?
- 執行程式碼。
- 按下"確定"按鈕,VBA程式碼將根據你的輸入調整投影片中所有圖片的大小。
- 輸入"H"或"W",以指定你要調整的圖片大小方向。輸入你想要調整的大小值,以公分為單位。
- 值得注意的是,上述VBA程式碼僅調整投影片中的圖片大小,並不會影響其他形狀或對象的大小。
在上述VBA程式碼中,有兩個比較重要的元素:LockAspectRatio和objPic.Type = msoPicture。
LockAspectRatio是一個布林值,當它設為msoTrue時,表示調整圖片的高度或寬度時需要鎖定圖片的比例。這意味著如果你調整圖片的高度,圖片的寬度也會相應地自動調整,以保持圖片的原始比例。這個選項很重要,因為它確保了圖片的外觀不會因為調整大小而失真或變形。
另一個重要的元素是objPic.Type = msoPicture。在PowerPoint中,一個投影片上可以有許多不同的形狀和對象,包括文字框、圖片、矩形等等。當我們使用VBA程式碼來調整投影片中的所有圖片大小時,我們需要確保我們只調整投影片上的圖片而不會影響其他形狀或對象。通過使用objPic.Type = msoPicture,我們可以確定正在處理的形狀是一個圖片,從而避免了對其他形狀或對象進行意外更改的風險。
留言
張貼留言