我是Excel的新手,我正在尝试编写一个宏来将多个Excel电子表格转换为多个PowerPoint幻灯片。到目前为止,我已经找到了一种从网站上的单个Excel工作表制作单个幻灯片的方法:
Option Explicit
Sub ExcelRangeToPowerPoint()
Dim rng As Excel.Range
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim myShapeRange As PowerPoint.Shape
'Copy Range from Excel
Set rng = ThisWorkbook.ActiveSheet.Range("A1:G17")
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, ppLayoutTitleOnly)
'Copy Excel Range
rng.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
'Set position:
myShapeRange.Left = 150
myShapeRange.Top = 186
'Clear The Clipboard
Application.CutCopyMode = False
End Sub
我只是想弄清楚,是否有一个宏可以循环遍历给定的文件夹/目录并将所有Excel文件转换为PowerPoint演示文稿?
答案 0 :(得分:3)
你了解代码吗?它将从单个单元格范围创建单个powerpoint幻灯片。如果您的工作簿文件有多张表怎么办?如果每张纸上的范围不同怎么办。
你的代码需要适应这个。
所以你要写代码