使用VBA将Excel范围粘贴到Powerpoint模板的某些幻灯片中 [英] Paste a range from Excel into certain slide of Powerpoint Template using VBA

查看:256
本文介绍了使用VBA将Excel范围粘贴到Powerpoint模板的某些幻灯片中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了好几个小时来寻找解决问题的各种建议解决方案,但找不到任何看起来可行的解决方案,或更可能的是,我对VBA的掌握是理解了我理解在线解决方案的能力.因此,我希望你们中的一个能帮助我解决问题.

I've spent a good few hours looking at various suggested solutions to my problem but cannot find anything that seems to do the job, or more likely, my grasp of VBA is understanding my ability to make sense of the online solutions. As such, I'm hoping one of you kind folk can help me resolve things.

我打开了一个Excel工作表,其中包含少量数据(标题和数字等)

I have an Excel Worksheet open that contains a small amount of data (Headings and numbers etc.)

我要复制此范围并将其粘贴(不是图片,如果需要,我可以在PowerPoint中对其进行格式化)粘贴到我已经创建的Powerpoint模板中的特定幻灯片(幻灯片2)上.

I want to copy this range and paste it (not as a picture, I want to be able to format it within powerpoint if necessary) on a particular slide (slide 2) in a Powerpoint template I have already created.

我的VBA使用以下代码根据模板正确打开一个新的演示文稿:

My VBA correctly opens up a new presentation based on the template using the following code:

    'Opens a PowerPoint Document from Excel

Dim objPPT As Object

Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True

'Change the directory path and file name to the location
'of your document

objPPT.Presentations.Open "C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm", Untitled:=msoTrue

但是,这就是我遇到的问题-打开演示文稿后,我不知道如何将Excel表格数据粘贴到正确的幻灯片中.我的数据在A1:D16

However, this is where I get stuck - I don't know how to paste the Excel tabular data into the correct slide once the presentation is open. My data is in range A1:D16

非常感谢您

推荐答案

尝试一下.我已将Excel工作表分配给一个变量(XLws),将PowerPoint幻灯片分配给另一个变量(PPslide).您可以在它们之间复制/粘贴对象.

Try out this one. I have assigned Excel worksheet to one variable (XLws) and PowerPoint slide to another (PPslide). You can Copy/Paste objects between them.

顺便说一句,您需要启用PowerPoint库.如果不这样做,请在您的VBA项目中转到工具->引用-> Microsoft PowerPoint 15.0对象库.

Btw, you need to have PowerPoint Library enabled. If you don't, in your VBA project go to Tools -> References -> Microsoft PowerPoint 15.0 Object Library.

Sub PPcopy()
Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide
Dim XLws As Worksheet

    Set XLws = ActiveSheet
    Set PPapp = New PowerPoint.Application
    Set PPpres = PPapp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm")
    PPapp.Visible = True
    Set PPslide = PPpres.Slides(2)
    XLws.Range("A1:D16").Copy
    PPslide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
    Application.CutCopyMode = False

End Sub

这篇关于使用VBA将Excel范围粘贴到Powerpoint模板的某些幻灯片中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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