如何将粘贴数据范围从 Excel 复制到幻灯片 [英] How to Copy paste data range from Excel to powerpoint slide

查看:52
本文介绍了如何将粘贴数据范围从 Excel 复制到幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写代码来复制和粘贴 Excel 数据范围,从 Excel 工作表到幻灯片,但我只能粘贴图像.

I am trying to prepare code to copy and paste excel data range from excel sheet to powerpoint slide but I am able to paste images only.

请帮忙提供合适的代码.我使用的代码如下:

Please help with the suitable code. The code I am using is as follows:

Sub WorkbooktoPowerPoint()

    Dim pp As Object
    Dim PPPres As Object
    Dim PPSlide As Object
    Dim Rng As Range

    Set pp = CreateObject("PowerPoint.Application")
    Set PPPres = pp.Presentations.Add
    pp.Visible = True
    Set Rng = ActiveSheet.Range("B1:J31")

    Rng.Copy

    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)

    PPSlide.Shapes.PasteSpecial ppPasteOLEObject
    PPSlide.Shapes(1).Select
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignTops, True
    pp.ActiveWindow.Selection.ShapeRange.Top = 65
    pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
    pp.ActiveWindow.Selection.ShapeRange.Width = 700

    pp.Activate
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set pp = Nothing

End Sub

推荐答案

让我感到惊讶的是,许多 PasteSpecial 选项通常无法从剪贴板或 PowerPoint 中使用.我认为有一种方法可以使用不同的方法来解决这个问题.而不是:

It still surprises me that many of the PasteSpecial options are not available form the clipboard or in PowerPoint generally. I think there is a way around this using a different method. Instead of:

PPSlide.Shapes.PasteSpecial ppPasteOLEObject

试试这个方法:

PPSlide.Parent.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"

我不确定要使用的正确 idMso 参数,但我会从那个开始,它看起来像我期望的那样工作:

I am not certain of the correct idMso argument to use but I would start with that, it looks like it works the way I would expect it to:

PowerPoint 结果

Excel 表格示例

如果没有,还有其他几个可能值得检查:

If not, there are several others that might be worth checking:

  • 粘贴源格式
  • 粘贴目的地主题
  • 粘贴嵌入
  • 粘贴ExcelTableSourceFormatting
  • PasteExcelTableDestinationTableStyle

与许多其他方法相比,此方法的文档记录不充分.Application.CommandBars property reference 没有提到 ExecuteMso 方法,我在此处找到了一些信息(以及在 SO 上我曾看到它使用过一两次):

This method is not as well-documented compared to many other methods. The Application.CommandBars property reference has nary a mention of the ExecuteMso method, which I found some information about here (and on SO where I have seen it used once or twice before):

要探索的 idMso 参数的完整列表,它们是一个相当大的可执行文件的一部分,用于流畅的功能区 UI 设计,我相信当前适用于 Office 2013:

The full list of idMso parameters to explore, which come as part of a rather large executable for use with fluent ribbon UI design, current for Office 2013 I believe:

http://www.microsoft.com/en-us/download/details.aspx?id=727

这篇关于如何将粘贴数据范围从 Excel 复制到幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆