excel - VBA 将多个 Powerpoint 演示文稿幻灯片保存为 JPG
问题描述
我有一个充满 PowerPoint 演示文稿的文件夹,并希望批量打开每一个并将每张幻灯片保存为图像。我发现了一些我在 Excel 中作为宏运行以保存为 PDF 的代码 - 我可以重新保存为 PDF,但是如何修改它以包括将幻灯片保存为 jpeg 图像?
Option Explicit
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Sub Converter()
Dim cnt As Integer, currfile As String
Dim TrimFile As String, Path As String, FilesInPath As String _
, MyFiles() As String, Fnum As Long
Dim CalcMode As Long, LPosition As Long
Dim StartTime As Date, EndTime As Date
ThisWorkbook.Activate
currfile = ActiveWorkbook.Name
Windows(currfile).Activate
Sheets("Sheet1").Activate
StartTime = Timer
Path = Range("C3").Text & "\"
FilesInPath = Dir(Path & "*.pp*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
On Error Resume Next
Set oPPTFile = oPPTApp.Presentations.Open(Path & MyFiles(Fnum))
On Error GoTo 0
If Not oPPTFile Is Nothing Then
LPosition = InStr(1, oPPTFile.Name, ".") - 1
TrimFile = Left(oPPTFile.Name, LPosition)
//here trying to save the slides as images
myslide = oPPTFile.Slides(1).Select
myslide.Export oPPTFile.Path & "\" & TrimFile & ".pdf"
On Error Resume Next
oPPTFile.ExportAsFixedFormat oPPTFile.Path & "\" & TrimFile & ".pdf", _
ppFixedFormatTypePDF, ppFixedFormatIntentPrint
End If
oPPTFile.Close
Next Fnum
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
oPPTApp.Quit
Set oPPTFile = Nothing
Set oPPTApp = Nothing
EndTime = Timer
MsgBox " Task succesfully completed in " & Format(EndTime - StartTime, "0.00") & " seconds"
End Sub
解决方案
您快到了。只需在路径和文件名之后添加 FilterName 参数。顺便说一句,我怀疑您是否需要在导出之前选择上一行中的幻灯片。
myslide.Export oPPTFile.Path & "\" & TrimFile & ".jpg", "JPG"
推荐阅读
- javascript - 反应过渡组过渡动画无法退出
- sql - 组合/折叠行与 group_by + 以列为下一行的条件
- python - pandas.io.sql 中哪个方法等价于 mysqlDB fetchone()
- node.js - Node js服务不返回任何东西
- excel - Excel 到 MS Access 连接:连接字符串中的空格问题
- powershell - VSCode 覆盖 PowerShell ExecutionPolicy
- r - 删除一系列时间戳,其中某个条件为 True
- ajax - Ajax:我需要将值从 php 脚本文件传递到 html 文件
- python - Python (Selenium) 从 HHPRED 中选择下拉列表
- javascript - Bootstrap 手风琴在 Angular 9 中不起作用