VBA Macro/VBA PowerPoint

파워포인트에 사용된 이미지 일괄 저장 매크로

루아흐뉴마 2017. 12. 14. 02:18
반응형

매크로 설명


  • 파워포인트 슬라이드에 있는 그림들을 일괄적으로 저장하는 코드를 응용.
  • 파워포인트에 사용된 모든 이미지를 특정 폴더 안에 그 폴더 이름으로 저장하는 매크로이다.


매크로 실행 동영상




VBA Code


Option Explicit
Sub picSaveAs()
Dim i As Long, cnt As Long
Dim savePath As String, folderName As String
Dim pic As Shape
Dim targetFormat As String
 
targetFormat = ".PNG"  '그림을 저장할 형식은 PNG
 
With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
    If .SelectedItems.Count = 0 Then    '취소시
        Exit Sub '매크로 종료
    Else
        savePath = .SelectedItems(1) & "\" '폴더경로 지정
        folderName = Split(.SelectedItems(1), "\")(UBound(Split(.SelectedItems(1), "\"))) '선택한 폴더 이름 따내기
    End If
End With
 
For i = 1 To ActivePresentation.Slides.Count
    For Each pic In ActivePresentation.Slides(i).Shapes
        If pic.Type = msoPicture Then '그림 파일이면
            With pic
                .LockAspectRatio = msoTrue '가로/세로 비율 고정
                '.Height = 200 '세로 길이 설정
                '.Width = ## 가로 길이는 비율에 따라 자동 설정하거나, 가로/세로 비율고정을 해제하고 직접 입력
                cnt = cnt + 1 '그림 카운트 증가
                .Export savePath & folderName & cnt & targetFormat, ppShapeFormatPNG, , , ppScaleToFit 'PNG 포맷으로 저장
            End With
        End If
    Next pic
Next i
 
cnt = 0
 
MsgBox "그림이 모두 저장되었습니다."
   
End Sub


 Copyright (2017) Ruahneuma. All Rights Reserved.



반응형