2016-06-30 2 views
1

하나의 PowerPoint 문서에서 모든 슬라이드의 모든 문자 간격을 한 번에 표준화하는 솔루션을 찾고 있습니다. 모든 모양에 대해 매크로를 작성했습니다 (). 테이블에 텍스트를 건너 뜁니다.. 그러나 범위에 msoTable을 추가하면 슬라이드 처리가 시작되지만 첫 번째 테이블에 도달하면 즉시 지정된 값이 범위를 벗어났습니다. 런타임 오류가 반환됩니다.VBA for Global PowerPoint 문자 간격 정규화

어떤 아이디어가 잘못 되었나요? 꽤 간단한 수정이라고 확신합니다.

Sub SpacingNormalization() 
On Error GoTo ErrMsg 
Dim shape As shape 
slideCount = ActivePresentation.Slides.Count 
For i = 1 To slideCount 
With ActivePresentation.Slides(i) 
.Select 
For Each shape In ActivePresentation.Slides(i).Shapes 
If shape.Type = msoPlaceholder Or shape.Type = msoTextBox Or shape.Type = msoAutoShape Or shape.Type = msoTable Then 
shape.Select 
ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange.Font.Spacing = 0 
End If 
ErrMsg: 
Next 
End With 
Next 
MsgBox ("All segments have been normalized!") 
End Sub 

모든 도움을 진심으로 감사드립니다. 미리 감사드립니다!

답변

0

PPT 자동화의 첫 번째 규칙 : 절대적으로 필요한 경우가 아니라면 절대로 선택하지 마십시오. PPT 자동화의 두 번째 규칙 : 당신은 거의 할 필요가 없습니다.

그에 따라 코드가 수정되었습니다.

그리고 대부분의 경우 셀을 사용하여 테이블 셀을 단계별로 수정해야합니다. 개조자는 더 많습니다. 아래를 참조하십시오 :

Sub SpacingNormalization() 
On Error GoTo ErrMsg 
' It's unwise to use PPT keywords as variable names: 
' Dim shape As shape 
Dim oSh as Shape 
Dim oSl as Slide 

For each oSl in ActivePresentation.Slides 
For Each oSh In oSl.Shapes 

If oSh.Type = msoPlaceholder Or oSh.Type = msoTextBox Or oSh.Type = msoAutoShape Then 

oSh.TextFrame2.TextRange.Font.Spacing = 0 

Else 
If oSh.Type = msoTable then 
    Call ProcessTable(oSh.Table) 
end if ' Table 
End If ' Other types 
Next ' oSh 
Next ' oSl 


NormalExit: 
MsgBox ("All segments have been normalized!") 
Exit Sub 
ErrMsg: 
Resume Next 

End Sub 

Sub ProcessTable(oTbl As Table) 

    Dim Col As Long 
    Dim Row As Long 

    With oTbl 
     For Col = 1 To .Columns.Count 
      For Row = 1 To .Rows.Count 
       .Cell(Row, Col).Shape.TextFrame2.TextRange.Font.Spacing = 0 
      Next 
     Next 
    End With 

End Sub 
+0

안녕 스티브, 입력 해 주셔서 감사합니다. 스크립트를 테스트 해보았지만 제대로 기능하지 않는 것 같습니다. PowerPoint의 VBA는 모든 도형 (이미 초기 스크립트에서 수행 할 수있는)에 대한 간격을 정교하게 수정하여 순환하지만 여전히 테이블을 수정하지는 않습니다. 두 번째 하위 호출을 건너 뛰고있는 것 같습니다. 편집기는이를 별도의 하위로 표시하므로 별도로 실행할 수는 없습니다. 단일 하위로 통합하려고했으나 실패했습니다. 내가 가진 (Case Is =와 함께) 새로운 기능이 작동하는 것 같지만 불행히도 처음부터 다시 작성해야했지만 지금은 완전히 다른 스크립트입니다. – Ilia

+0

내 잘못 ... 편집 된 버전보기; Call ProcessTable (oSh)을 Call ProcessTable (oSh.Table)으로 변경했으며 현재 작동합니다. –

+0

또 하나 기억해야 할 점은 유형 자리 표시자인 모양도 표일 수 있다는 것입니다. 따라서 PlaceholderFormat 객체에서 ContainedType 속성을 확인하거나 HasTable 속성을 사용할 수 있습니다. –

0

여기에 제가 생각해 냈습니다. 단 하나의 하위에 있으며 조금 더 직설적 인 것 같습니다 :

Sub SpacingNormalization() 
     On Error GoTo Errmsg 
     Dim oshp As shape 
     Dim otbl As Table 
     Dim Rws As Integer 
     Dim Clms As Integer 
     Dim osld As Slide 
     For Each osld In ActivePresentation.Slides 
      For Each oshp In osld.Shapes 
       Select Case oshp.HasTable 
       Case Is = True 
        Set otbl = oshp.Table 
        For Rws = 1 To otbl.Rows.Count 
         For Clms = 1 To otbl.Columns.Count 
          otbl.Cell(Rws, Clms).shape.TextFrame2.TextRange.Font.Spacing = 0 
         Next Clms 
        Next Rws 
       Case Is = False 
        If oshp.HasTextFrame Then 
         If oshp.TextFrame.HasText Then 
          oshp.TextFrame2.TextRange.Font.Spacing = 0 
         End If 
        End If 
       End Select 
      Next oshp 
     Next osld 
     MsgBox ("All segments have been normalized!") 
     Exit Sub 
Errmsg: 
     MsgBox "Error" 
    End Sub