【问题标题】:Replace a text box with a placeholder (Title or Body)用占位符(标题或正文)替换文本框
【发布时间】:2020-11-02 05:58:05
【问题描述】:

我收到了一个包含多张幻灯片的 PowerPoint 文件,这些幻灯片应该是模板(设计 - 自定义布局),但实际上是普通幻灯片。

将它们转换为 SlideMaster 和自定义布局并手动将标题和正文(文本框)替换为实际占位符是一件很痛苦的事情。

所以我用这个脚本来加快这个过程。

如果有人有更好的方法,欢迎提出。

【问题讨论】:

    标签: vba powerpoint shapes slide


    【解决方案1】:

    必须寻找解决方法来获取customlayout 对象。

    缺少一些东西,例如错误处理。

    要对其进行测试,请将文本框复制到幻灯片母版布局幻灯片中,选择它并运行 ReplaceWithPHTitle 宏

    Option Explicit
    
    Public Sub ReplaceWithPHTitle()
    
        ReplaceTexboxWithPlaceholder ppPlaceholderTitle
    
    End Sub
    
    Public Sub ReplaceWithPHBody()
    
        ReplaceTexboxWithPlaceholder ppPlaceholderBody
    
    End Sub
    
    Private Sub ReplaceTexboxWithPlaceholder(ByVal placeholderType As PpPlaceholderType)
    
        Dim targetLayout As CustomLayout
        Dim activeShape As Shape
        Dim newPlaceHolder As Shape
        
        Set activeShape = ActiveWindow.Selection.ShapeRange(1)
        Set targetLayout = activeShape.Parent
        
        Set newPlaceHolder = targetLayout.Shapes.AddPlaceholder(Type:=placeholderType, Left:=activeShape.Left, Top:=activeShape.Top, Width:=activeShape.Width + 15, Height:=activeShape.Height)
        
        With newPlaceHolder.TextFrame
    
            .TextRange.Font.Name = activeShape.TextFrame.TextRange.Font.Name
            .TextRange.Characters.Font.Color.RGB = activeShape.TextFrame.TextRange.Characters.Font.Color.RGB
            .TextRange.Font.Size = activeShape.TextFrame.TextRange.Font.Size
            .TextRange.Font.Bold = activeShape.TextFrame.TextRange.Font.Bold
            .TextRange.ParagraphFormat.Bullet.Type = activeShape.TextFrame.TextRange.ParagraphFormat.Bullet.Type
            .TextRange.ParagraphFormat.SpaceWithin = activeShape.TextFrame.TextRange.ParagraphFormat.SpaceWithin
            .TextRange.ParagraphFormat.Alignment = activeShape.TextFrame.TextRange.ParagraphFormat.Alignment
            .TextRange.ParagraphFormat.SpaceBefore = activeShape.TextFrame.TextRange.ParagraphFormat.SpaceBefore
            .TextRange.ParagraphFormat.SpaceAfter = activeShape.TextFrame.TextRange.ParagraphFormat.SpaceAfter
            .TextRange.ParagraphFormat.BaseLineAlignment = activeShape.TextFrame.TextRange.ParagraphFormat.BaseLineAlignment
            .TextRange.Text = activeShape.TextFrame.TextRange.Text
        End With
        
        With newPlaceHolder.TextFrame2
            .TextRange.Font.Spacing = activeShape.TextFrame2.TextRange.Font.Spacing
        End With
        
        newPlaceHolder.ZOrder msoSendToBack
        newPlaceHolder.Select
        
    End Sub
    

    也欢迎任何改进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 2012-12-07
      • 2022-11-25
      • 2010-09-29
      • 2020-05-27
      相关资源
      最近更新 更多