VBA Macro/VBA PowerPoint

[파워포인트 VBA] 전체 슬라이드 글씨 색깔 바꾸기

루아흐뉴마 2018. 8. 3. 12:00
반응형


매크로 설명


  • 파워포인트 각 슬라이드의 텍스트 서식 중에서 색깔을 일괄적으로 변경하는 매크로이다.
  • 파워포인트 슬라이드가 많아질수록 직접 변경하기 번거로울 때 사용하면 좋다.
  • 변경되는 Shape는 텍스트를 가진 텍스트박스, 도형, 표의 모든 텍스트이다.
  • 파워포인트가 실행되어 있어야 하고, 코드는 엑셀에 작성하여 제어하는 방식이다.
  • 엑셀 개발자도구에서 PowerPoint Object Library를 참조해주어야 한다.
  • ※ 차트의 글씨 색깔은 변경하지 않는다. (참고)


적용 결과




매크로 실행 동영상




VBA Code


Option Explicit
Sub c_changer()
Dim pptRef As PowerPoint.Application
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim tbl As PowerPoint.Table
Dim i As Long, j As Long

On Error Resume Next
Set pptRef = GetObject(, "PowerPoint.Application")
If Err.Number > 0 Then '파워포인트가 실행되어있지 않으면,
  MsgBox "파워포인트를 실행하세요", vbOKOnly
  Exit Sub '매크로 종료
End If
On Error GoTo 0

For Each sld In pptRef.ActivePresentation.Slides '모든 슬라이드(sld)를 돌면서
  For Each shp In sld.Shapes  '슬라이드 내의 개체(shp)를 돌면서
    
    If shp.TextFrame2.HasText Then  '그룹으로 된 경우
      shp.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
    End If
    
    If shp.HasTextFrame Then  '텍스트 개체이면
      shp.TextFrame.TextRange.Font.Color = RGB(0, 0, 0)
    End If
    
    If shp.HasTable Then  '표이면
      Set tbl = shp.Table 'tbl을 표 개체로 지정
        For i = 1 To tbl.Rows.Count
          For j = 1 To tbl.Columns.Count  '각 셀을 순환하면서
            tbl.Cell(i, j).Shape.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
          Next j
      Next i
    End If
  Next
Next

End Sub








 Copyright (2018) Ruahneuma. All Rights Reserved.


반응형