【发布时间】:2017-11-21 19:30:44
【问题描述】:
我有以下代码,我尝试对其进行修改,使其遍历 excel 中的列表,打开列表中的每个 ppt 文件并将其复制到新的 ppt 文件中。但是它被挂断了,并且在循环过程中出现了错误。
Sub tmp()
'Set a VBE reference to Microsoft PowerPoint Object Library
On Error GoTo ErrorHandler
Dim PPApp As PowerPoint.Application
Dim i, j As Integer
Dim pres1, new_pres As PowerPoint.Presentation
Dim oslide, s, oSld As PowerPoint.Slide
Dim oShape, oSh, oshp As PowerPoint.Shape
Dim wb As Workbook
Dim list As Worksheet
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
Set new_pres = PPApp.Presentations.Add
Set wb = ThisWorkbook
Set list = wb.Worksheets("Powerpoint File List")
LastRow = list.Range("A" & Rows.Count).End(xlUp).Row
new_pres.PageSetup.SlideSize = ppSlideSizeOnScreen
' this is not working
For i = 1 To 1 ' LastRow
filepath = list.Range("A" & i).Value
Set pres1 = PPApp.Presentations.Open(filepath)
For j = 1 To pres1.Slides.Count
pres1.Slides.shapes(j).Copy
new_pres.Slides.Paste
new_pres.Application.CommandBars.ExecuteMso "PasteSourceFormatting")
Next j
pres1.Close
Set pres1 = Nothing
Next I
NormalExit:
Exit Sub
ErrorHandler:
Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
vbOKOnly, "Error inserting files")
Resume NormalExit
End Sub
【问题讨论】:
-
请说明错误是什么以及发生在哪一行。
-
如果我将 j 循环更改为以下内容:pres1.Slides(j).Copy new_pres.Slides.Paste new_pres.Application.CommandBars.ExecuteMso "PasteSourceFormatting") 然后它复制第一页powerpoint 被复制的 powerpoint 的页数。
-
“复制那个”是什么意思?对于单个文件,您希望看到什么?
-
如果您要复制文件,为什么要打开它们?批处理文件复制它们并Shell执行?
-
这超出了我的技能水平,你有例子吗?我是自学成才,已经做了 2 个月。
标签: vba excel powerpoint