我以前从未在这里发布过,所以我想尝试一下。我有一个已经使用了一年多的宏,在本周初它开始给我带来一些问题。它要么只是拉入每个Powerpoint的第一张幻灯片,要么会给我一个运行时错误“幻灯片(未知成员):无效的请求。剪贴板为空或包含了可能无法粘贴到此处的数据。”
如果我仅使用F8单步执行宏,则该宏工作正常,唯一的问题是是否尝试运行它。这可能是非常明显的,因为我是VBA的新手。感谢您的帮助!
Public Sub DoFiles()
Dim strFileName As String
Dim strFolderName As String
Dim objPresentation As Presentation
'set default directory here if needed
strFolderName = "Target Folder"
strFileName = Dir(strFolderName & "\*.ppt*")
Do While Len(strFileName) > 0
Set objPresentation = Presentations.Open(strFolderName & "\" &
strFileName)
On Error Resume Next
Dim i As Integer
For i = 1 To objPresentation.Slides.Count
objPresentation.Slides.Item(i).Copy
Presentations.Item(1).Slides.Paste
Presentations.Item(1).Slides.Item(Presentations.Item(1).Slides.Count).Design
= _
objPresentation.Slides.Item(i).Design
Next i
objPresentation.Close
strFileName = Dir
Loop
End Sub
答案 0 :(得分:0)
史蒂夫的建议工作吗?
Public Sub DoFiles()
Dim strFileName As String
Dim strFolderName As String
strFolderName = "Target Folder"
strFileName = Dir(strFolderName & "\*.ppt*")
Do While Len(strFileName) > 0
ActivePresentation.Slides.InsertFromFile strFolderName & "\" & strFileName, ActivePresentation.Slides.Count
strFileName = Dir
Loop
End Sub