我对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演示文稿?
发布于 2015-06-29 21:00:05
你明白密码吗?它将从单个单元格创建一个powerpoint幻灯片。如果您的工作簿文件有许多工作表,怎么办?如果每张纸上的范围都不同呢。
您的代码将需要容纳这一点。
所以你会写代码
你是急着要把这事自动化的吗?如果您只需要这样做一次,您可能是最好的手工操作吗?当然,这取决于文件的数量和执行的频率。
要回答您的问题,请参阅这里,它使用dir查找文件夹中的文件。但是需要更多的代码才能做到这一点!
可能有一个工具可以在web...eg 这里上使用,我还没有起诉它,但这是一个常见的需求。
https://stackoverflow.com/questions/31124877
复制相似问题