【问题标题】:macro create excel table to powerpoint宏创建 Excel 表到 powerpoint
【发布时间】:2020-07-02 16:06:12
【问题描述】:

我是使用 VBA 的新手,所以以前有可能这样做过,但我找不到关于此的讨论。我已经创建了一个模板 ppt,我需要将表格添加到特定的幻灯片中(见图)。

创建表格并将其运行到 Powerpoint 中会更容易吗?还是将其与 PPT 中可以填充的预先存在的表格连接起来?

【问题讨论】:

  • “看图片”...什么图片?
  • @Joel 我可以看到,你看不到吗?
  • 您可能想查看此Link

标签: excel vba powerpoint


【解决方案1】:

您有几个选择。您可以将 Excel 范围导出为 OLE 对象、PowerPoint 表格对象或链接的 OLE 对象。每个都有自己的优点和缺点,但在您的情况下,如果格式不必完全匹配,我会将其粘贴为表格。

这里有一些代码将演示如何使用 VBA 从 Excel 将一系列单元格粘贴到 PowerPoint。

Sub ExportMultipleRangeToPowerPoint_Method2()

    'Declare PowerPoint Variables
    Dim PPTApp As PowerPoint.Application
    Dim PPTPres As PowerPoint.Presentation
    Dim PPTSlide As PowerPoint.Slide
    Dim SldArray as Variant
    
    'Declare Excel Variables
    Dim ExcRng As Range
    Dim RngArray As Variant
    
    'Populate our array. This will define two ranges that exist in Sheet 1.
    'This also populates our slide array which specifies which slide each range is pasted on.
    'YOU WILL NEED TO CHANGE THIS IN ORDER FOR IT TO WORK ON YOURS!
    RngArray = Array(Sheet1.Range("A1:F8"), Sheet1.Range("A10:F18"))
    SldArray = Array(1, 2)

    'Create a new instance of PowerPoint
    Set PPTApp = New PowerPoint.Application
        PPTApp.Visible = True
    
    'Create a new Presentation
    Set PPTPres = PPTApp.Presentations.Add
    
    'Loop through the range array, create a slide for each range, and copy that range on to the slide.
    For x = LBound(RngArray) To UBound(RngArray)
    
        'Set a reference to the range
        Set ExcRng = RngArray(x)
        
        'Copy Range
        ExcRng.Copy
        
        'Enable this line of code if you receive an error about the range not being in the clipboard - This will fix that error by pausing the program for ONE Second.
        'Application.Wait Now + #12:00:01 AM#
        
        'GRAB AN EXISTING SLIDE.
        Set PPTSlide = PPTPres.Slide(SldArray(x))
        
        'Paste the range in the slide as a Table (Default).
        PPTSlide.Shapes.PasteSpecial DataType:=ppPasteDefault
    
    Next x

End Sub

同样,这实际上取决于您更新它的频率,但大多数时候我会敦促人们在使其变得更难之前保持它更容易。如果您需要更多的分步演练,我在 YouTube 上确实有一个系列,您可以跟着学习。如果您想做更高级的事情,例如定位甚至粘贴为不同的数据类型,这将特别有用。这是播放列表:Excel to PowerPoint

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 2011-12-12
    相关资源
    最近更新 更多