用 VBA 实现在 PPT 最下边加个进度条,方便查看进行到总长度的多少,
抓住了听讲人的心理:“啥时候才能讲完啊?”
进度条只能体现已播放的幻灯片张数,不能用于计时。

打开 PPT,按 Alt+F8 新建个宏,随便取个宏名,不用改宏作用区域,
点“创建”,删除模块里的内容,把代码复制过去。
(按 Alt+F11 之后插入模块也可以)

进度条宏的作者是水木社区的dukenuke

Sub ProgressBar()
' by dukenuke@newsmth.net
' Sun Jul 11 00:06:13 2010

    Dim mySlides As Slides
    Dim pageBar As ShapeRange
    Dim pageSHower As Shape
    Dim pageWidth, pageHeight, pageStep
    
    Set mySlides = Application.ActivePresentation.Slides

    pageWidth = Application.ActivePresentation.SlideMaster.Width
    pageHeight = Application.ActivePresentation.SlideMaster.Height
    pageStep = pageWidth / mySlides.Count

    On Error Resume Next

    For i = 2 To mySlides.Count
        Set pageBar = mySlides.Item(i).Shapes.Range(Array())
        Set pageBar = _
           mySlides.Item(i).Shapes.Range(Array("RectanglePageNum"))

        If IsNull(pageBar) Or pageBar.Count = 0 Then GoTo newBar
        Set pageSHower = pageBar.Item(1)
        GoTo nextPage

newBar:
        Set pageSHower = mySlides.Item(i).Shapes.AddShape( _
                           msoShapeRectangle, 0, _
                           pageHeight - 3, i * pageStep, 3)
        pageSHower.Name = "RectanglePageNum"

nextPage:
        pageSHower.Fill.ForeColor.RGB = RGB(179, 162, 199)
        pageSHower.Line.Visible = msoFalse
        pageSHower.Width = i * pageStep
        pageSHower.Top = pageHeight - 3
        pageSHower.Left = 0
        pageSHower.Height = 3

    Next
End Sub

 

颜色尺寸可以更改,现在的高度是3,在页面最下方,颜色是淡紫色。

PowerPoint 2007/2010 需要另存为带宏的演示文稿,还可以把宏按钮添加
到快速访问工具栏。

开始讲 PPT 前先运行宏(按 Alt+F8 或用快速访问工具栏),运行一次即可,
播放幻灯片时就会自动加上进度条,只有第一页不加,会自动根据当前页
面数刷新进度。

注:增减幻灯片(总页数改变)后要重新运行一次宏。

 

 

2010-9-12,对宏进行更新:

 

Sub ProgressBar()
' bydukenuke@newsmth.net
' Sun Jul 11 00:06:13 2010
'
' Update by oicu#lsxk.org
' 2010/9/12 20:44
' 对首页以及隐藏幻灯片进行处理

    Dim mySlides As Slides
    Dim pageBar As ShapeRange
    Dim pageSHower As Shape
    Dim pageWidth, pageHeight, pageStep
    Dim MyArray() As Variant  '增加一个数组以便统计隐藏的幻灯片
    Dim i, j, k
    j = 0
    k = 0

    Set mySlides = Application.ActivePresentation.Slides

    pageWidth = Application.ActivePresentation.SlideMaster.Width
    pageHeight = Application.ActivePresentation.SlideMaster.Height
    ' pageStep = pageWidth / mySlides.Count

    ReDim MyArray(mySlides.Count, 0)
    
    For i = 1 To mySlides.Count'统计隐藏的幻灯片数
        If mySlides.Item(i).SlideShowTransition.Hidden = True Then
            j = j + 1
            MyArray(i, 0) = 1
        Else
            MyArray(i, 0) = 0
        End If
    Next

    '除去首页和隐藏的幻灯片后计算进度条长度增量
    If mySlides.Count - 1 - j > 0 Then
        pageStep = pageWidth / (mySlides.Count - 1 - j)
    Else
        pageStep = 0
    End If

    On Error Resume Next

    For i = 1 To mySlides.Count    ' 改为从1开始
        k = k + MyArray(i, 0)      ' 计算当前隐藏的幻灯片数
        Set pageBar = mySlides.Item(i).Shapes.Range(Array())
        Set pageBar = _
           mySlides.Item(i).Shapes.Range(Array("RectanglePageNum"))

        If IsNull(pageBar) Or pageBar.Count = 0 Then GoTo newBar
        Set pageSHower = pageBar.Item(1)
        GoTo nextPage

newBar:
        Set pageSHower = mySlides.Item(i).Shapes.AddShape( _
                           msoShapeRectangle, 0, _
                           pageHeight - 3, i * pageStep, 3)
        pageSHower.Name = "RectanglePageNum"

nextPage:
        pageSHower.Fill.ForeColor.RGB = RGB(179, 162, 199)
        pageSHower.Line.Visible = msoFalse
        ' pageSHower.Width = i * pageStep
       ' 计算进度条长度时除去首页和隐藏的幻灯片
        pageSHower.Width = (i - 1 - k) * pageStep
        pageSHower.Top = pageHeight - 3
        pageSHower.Left = 0
        pageSHower.Height = 3
        ' 删除首页和隐藏的幻灯片的进度条
        If i = 1 Or MyArray(i, 0) = 1 Then pageSHower.Delete
    Next
End Sub  

 

WPS演示安装了vba之后同样可以使用宏制作进度条,不过要修改几个地方才能使用。

 

Sub ProgressBar()
' by oicu#lsxk.org
' 2010/9/18 22:48
' For WPS 演示

    Dim mySlides As Slides
    ' Dim pageBar As ShapeRange
    Dim pageSHower As Shape
    Dim pageWidth, pageHeight, pageStep
    Dim MyArray() As Variant  '增加一个数组以便统计隐藏的幻灯片
    Dim i, j, k
    j = 0
    k = 0

    Set mySlides = Application.ActivePresentation.Slides

    ' pageWidth = Application.ActivePresentation.SlideMaster.Width
    ' pageHeight = Application.ActivePresentation.SlideMaster.Height
    ' WPS演示不能取得母板的长宽,改成PageSetup
    pageWidth = Application.ActivePresentation.PageSetup.SlideWidth
    pageHeight = Application.ActivePresentation.PageSetup.SlideHeight

    ReDim MyArray(mySlides.Count, 0)
   
    For i = 1 To mySlides.Count ' 统计隐藏的幻灯片数
        If mySlides.Item(i).SlideShowTransition.Hidden = True Then
            j = j + 1
            MyArray(i, 0) = 1
        Else
            MyArray(i, 0) = 0
        End If
    Next

    ' 除去首页和隐藏的幻灯片后计算进度条长度增量
    If mySlides.Count - 1 - j > 0 Then
        pageStep = pageWidth / (mySlides.Count - 1 - j)
    Else
        pageStep = 0
    End If

    On Error Resume Next

    For i = 1 To mySlides.Count    ' 改为从1开始
        k = k + MyArray(i, 0)      ' 计算当前隐藏的幻灯片数
        
        ' WPS演示会自动增加数字在RectanglePageNum名称后面,
        ' 无法用下面的方法清除原有的进度条!只能循环删除。
        For j = 1 To mySlides.Item(i).Shapes.Count
            If VBA.Left(mySlides.Item(i).Shapes(j).Name, 16) = _
            "RectanglePageNum" Then mySlides.Item(i).Shapes(j).Delete
        Next
        
        ' Set pageBar = mySlides.Item(i).Shapes.Range(Array())
        ' Set pageBar = _
            mySlides.Item(i).Shapes.Range(Array("RectanglePageNum"))

        ' If IsNull(pageBar) Or pageBar.Count = 0 Then GoTo newBar
        ' Set pageSHower = pageBar.Item(1)
        ' GoTo nextPage

newBar:  ' mso改为kso
        Set pageSHower = mySlides.Item(i).Shapes.AddShape( _
                           ksoShapeRectangle, 0, _
                           pageHeight - 3, i * pageStep, 3)
        pageSHower.Name = "RectanglePageNum"

nextPage:
        pageSHower.Fill.ForeColor.RGB = RGB(179, 162, 199)
        pageSHower.Line.Visible = ksoFalse  ' mso改为kso
        ' 计算进度条长度时除去首页和隐藏的幻灯片
        pageSHower.Width = (i - 1 - k) * pageStep
        pageSHower.Top = pageHeight - 3
        pageSHower.Left = 0
        pageSHower.Height = 3
        ' 删除首页和隐藏的幻灯片的进度条
        If i = 1 Or MyArray(i, 0) = 1 Then pageSHower.Delete
    Next
End Sub

 

 

示例:

《Marry Me》   http://v.youku.com/v_show/id_XMTg4ODY3MjE2.html

 

转自:

  顺顺在线.用 VBA 实现在 PPT 最下边加个进度条.http://hi.baidu.com/zunx/blog/item/811f35d331b95f143bf3cf03.html

 

转载于:https://www.cnblogs.com/ccdc/archive/2012/05/31/2528869.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐