DOC+VBA
슬라이드의 특정 이름의 개체 속의 텍스트를 워드 문서로 출력
쵸코난
2023. 12. 6. 00:55
아래 코드는 현재 파워포인트 파일의 모든 슬라이드에서
개체의 이름이 'Google shape;'로 시작하는 모든 개체를 찾아
그 안의 텍스트를 같은 이름의 워드 파일에 계속 쭉 출력해주는 예시입니다.
찾을 개체 이름에는 *나 ? 같은 문자를 사용할 수 있습니다.
워드 문서에 출력시 각 슬라이드 번호는 구분을 위해 진한 글씨로 출력합니다.
기본 글자크기는 15입니다.
Option Explicit
'찾을 도형 이름
'Const TargetShape = "텍스트 개체틀 1*"
Const TargetShape = "Google Shape;*"
Sub Extract2Docx()
'Dim W As Word.Application, D As Word.Document
Dim W As Object, D As Object
Dim n As Integer, m As Integer
Dim T As Variant
Dim docFile As String
Dim sld As Slide, shp As Shape
Dim myRange As Object
'Dim myRange As Word.Range
docFile = ActivePresentation.FullName
docFile = Left(docFile, InStrRev(docFile, ".")) & "docx"
Set W = CreateObject("Word.Application")
W.Visible = True
Set D = W.Documents.Add(Visible:=True)
Set myRange = D.Content
myRange.Font.Size = 15
'슬라이드내 개체 순환
For Each sld In ActivePresentation.Slides
'슬라이드 구분 출력
With myRange
.InsertParagraphAfter
.Collapse 0 'Word.wdCollapseEnd
.Text = "Slide #" & sld.SlideIndex
.Font.Bold = True
.Collapse 0 'Word.wdCollapseEnd
.InsertParagraphAfter
End With
For Each shp In sld.Shapes
'도형이름이 특정이름과 비슷하다면 내용 출력
If shp.Name Like TargetShape Then
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
With myRange
.InsertAfter shp.TextFrame.TextRange
.InsertAfter vbVerticalTab
End With
End If
End If
End If
Next shp
Next sld
'문서 저장 및 종료
D.SaveAs2 FileName:=docFile
'D.Close True '저장
Set D = Nothing
'W.Quit False
Set W = Nothing '초기화
End Sub
샘플 ppt 파일입니다.
샘플 파일의 템플릿은 PPTMON.COM 입니다.
( Presentation template by PPTMON.COM )