赞
踩
ppt是画科研插图的优秀工具,能够很方便的导出为pdf并插入latex,但手动通过“另存为-格式-pdf-当前页-确定”将一页ppt保存为一个pdf文件要选择多个选项,稍显繁琐,故编写了一小段vba脚本来自动化这一步骤。
执行该宏,可很方便的将ppt页导出为无边框的pdf文件:
示例文件下载:
链接: https://pan.baidu.com/s/1QGTC5a5kD35lD-7_EdPqpQ 提取码: kd45
首先确保将ppt保存为启用宏的pptm文件格式。
开启“开发工具”选项卡
打开vb编辑器填入如下代码并保存:
Sub 逐张存储() 'https://stackoverflow.com/questions/17929124/export-each-slide-of-powerpoint-to-a-separate-pdf-file Dim strNotes As String, savePath As String Dim oPPT As Presentation, oSlide As Slide Dim sPath As String, sExt As String Set oPPT = ActivePresentation 'sPath = oPPT.FullName & "_Slide_" sPath = oPPT.Path sExt = ".pdf" For Each oSlide In oPPT.Slides i = oSlide.SlideNumber oSlide.Select strNotes = oSlide.NotesPage. _ Shapes.Placeholders(2).TextFrame.TextRange.Text 'MsgBox strNotes 'MsgBox Len(strNotes) = 0 savePath = sPath & "\" & strNotes & sExt If Not Len(strNotes) = 0 Then oPPT.ExportAsFixedFormat _ Path:=savePath, _ FixedFormatType:=ppFixedFormatTypePDF, _ RangeType:=ppPrintSelection Shell "pdfcrop " & savePath & " " & savePath End If Next Set oPPT = Nothing End Sub Sub 选中存储() Dim strNotes As String, savePath As String Dim oPPT As Presentation, oSlide As Slide Dim sPath As String, sExt As String Set oPPT = ActivePresentation 'sPath = oPPT.FullName & "_Slide_" sPath = oPPT.Path sExt = ".pdf" Set oSlide = Application.ActiveWindow.View.Slide strNotes = oSlide.NotesPage. _ Shapes.Placeholders(2).TextFrame.TextRange.Text savePath = sPath & "\" & strNotes & sExt If Not Len(strNotes) = 0 Then oPPT.ExportAsFixedFormat _ Path:=savePath, _ FixedFormatType:=ppFixedFormatTypePDF, _ RangeType:=ppPrintSelection Shell "pdfcrop " & savePath & " " & savePath End If Set oPPT = Nothing End Sub
在宏管理器中双击脚本即可执行。
其中”逐张存储“的功能是遍历ppt中的所有页,逐个保存为pdf文件。其中文件名为每页的备注内容。
如备注为空则跳过该页。此外,对每个保存的pdf文件,还将执行pdfcrop(latex套件提供的一个pdf剪裁工具),将pdf的白边减裁掉,方便贴到latex中。
”选中存储“功能类似,但仅对选中的那一页ppt进行处理。
为更加方便的使用该宏,可将宏添加到自定义菜单。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。