【工具】pptx自动插入当前日期和自动页码

使用VBA代码直接修改

使用方式,ppt界面,同时按住Alt + F11两个键 ,弹出的页面中,点击文件名称,然后右键创建模块 ,见下图

接着把下面的代码复制粘贴到模块文件中,再点击F5键即可。

vba 复制代码
Sub AddFooter()
    Dim s As Slide
    Dim sh As Shape
    Dim n As Integer
    Dim i As Integer
    
    ' 获取总页数
    n = ActivePresentation.Slides.Count
    
    ' 遍历所有幻灯片
    For i = 1 To n
        Set s = ActivePresentation.Slides(i)
        
        ' ==============================================
        ' 【关键修复】强力删除所有旧页脚,不管内容是什么
        ' ==============================================
        For j = s.Shapes.Count To 1 Step -1
            Set sh = s.Shapes(j)
            If sh.Type = msoTextBox Then
                ' 判断位置:只要是你页脚的位置,就全部删除
                If sh.Top > 500 And sh.Left > 800 Then
                    sh.Delete
                End If
            End If
        Next j
        
        ' 添加新页脚
        Set sh = s.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=755, Top:=515, Width:=300, Height:=30)
        
        ' 内容:日期 + 时间 + 页码
        With sh.TextFrame.TextRange
            .Text = Format(Date, "yyyy-mm-dd") & "   第 " & CStr(i) & "/" & CStr(n) & " 页"
            .Font.Name = "微软雅黑"
            .Font.Size = 16
            .Font.Color = vbWhite   ' 白色字体
        End With
        
        ' 垂直居中
        sh.TextFrame2.VerticalAnchor = msoAnchorMiddle
        
    Next i
    
    MsgBox "✅ 所有幻灯片页脚更新完成!"
End Sub
相关推荐
spencer_tseng11 天前
excel 2003 [Cell division function]
excel·office
lazyn13 天前
解决 uTools 本地搜索无法调用 Everything 1.5a 的问题
插件·everything·办公·utools
IT技术分享社区13 天前
微软Office 2024离线版安装指南与功能亮点介绍
microsoft·微软技术·office·电脑干货
SunkingYang1 个月前
鼠标双击打开PPT里插入的附件文件时,报错:Office已阻止访问以下嵌入对象,以便保护你的安全
powerpoint·报错·附件·office·打开·已阻止访问·嵌入对象
johnny2331 个月前
浏览器Office解决方案:Office-Website、SuperDoc
office
humors2211 个月前
40款办公助手软件分享
电脑·工具·程序·软件·笔记本·办公·高效
天若有情6731 个月前
程序员原创|借鉴JS事件冒泡,根治电脑文件混乱的“冒泡整理法”
开发语言·javascript·windows·ecmascript·电脑·办公·日常
九成宫1 个月前
Outlook使用
windows·笔记·outlook·办公
pcplayer1 个月前
非常好用的 Excel 读写控件
excel·delphi·office
weitingfu2 个月前
Excel VBA 入门到精通(十):实战项目——自动化报表系统开发
ai·信息可视化·自动化·excel·vba·office·报表系统