VBA使用頻度の高いコード(2):エクセル上の写真の縮小
エクセル上の写真の縮小
エクセル上の写真を縮小するためのマクロ
===============================
Sub 写真縮小()
ActiveSheet.Unprotect
Dim shp As Shape
Dim x As Double
Dim y As Double
Application.ScreenUpdating = False
If MsgBox("画像データを圧縮しますか?", vbQuestion + vbOKCancel) = vbCancel Then
MsgBox "終了します。"
Exit Sub
End If
'実行継続
For Each shp In ActiveSheet.Shapes
'写真判定
If shp.Type = msoPicture Then
With shp
x = .Left
y = .Top
.Cut
End With
ActiveSheet.PasteSpecial Format:="図 (JPEG)"
With Selection
.Left = x
.Top = y
End With
End If
Next
ActiveSheet.Protect
End Sub
===============================