首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将文件夹中的Excel文件转换(或复制)为相应的PowerPoint演示文稿的VBA代码

将文件夹中的Excel文件转换(或复制)为相应的PowerPoint演示文稿的VBA代码
EN

Stack Overflow用户
提问于 2015-06-29 20:23:20
回答 1查看 142关注 0票数 0

我对Excel非常陌生,我正在尝试编写一个宏来将多个Excel电子表格转换为多个PowerPoint幻灯片。到目前为止,我已经找到了一种方法,可以从网站的单个Excel工作表中制作个人幻灯片:

代码语言:javascript
复制
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演示文稿?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-29 21:00:05

你明白密码吗?它将从单个单元格创建一个powerpoint幻灯片。如果您的工作簿文件有许多工作表,怎么办?如果每张纸上的范围都不同呢。

您的代码将需要容纳这一点。

所以你会写代码

  1. 循环遍历文件夹中的每个excel文件。
  2. 循环遍历文件中的每个工作表
  3. 将新幻灯片添加到当前工作表的一个powerpoint文件中。
  4. 查找当前工作表的范围,并将范围添加到幻灯片中。

你是急着要把这事自动化的吗?如果您只需要这样做一次,您可能是最好的手工操作吗?当然,这取决于文件的数量和执行的频率。

要回答您的问题,请参阅这里,它使用dir查找文件夹中的文件。但是需要更多的代码才能做到这一点!

可能有一个工具可以在web...eg 这里上使用,我还没有起诉它,但这是一个常见的需求。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31124877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档