简体   繁体   English

在EXCEL 2010中复制和粘贴范围VBA PowerPoint

[英]Copy and Paste Range VBA PowerPoint in EXCEL 2010

This is the code that I am currently using. 这是我目前使用的代码。 I want to copy and paste a range to a specific powerpoint. 我想将范围复制并粘贴到特定的powerpoint。 I can do this fine using the following code but the quality is not very good and I was hoping there is another way around this. 我可以使用下面的代码做到这一点,但质量不是很好,我希望有另一种方法来解决这个问题。

Sub This ()
Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide

        ' Reference existing instance of PowerPoint
Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Desktop\Template.pptx")


Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
Sheets("Test").Select
Range("B6:Q46").CopyPicture
' Paste the range
With PPPres.Slides(18).Shapes.PasteSpecial
                .Top = 86.8969
                .Left = 19.98417
                .Height = 150.7964
                .Width = 600.5262
End With
End Sub

I have tried this: 我试过这个:

Sheets("Test").Select
Range("B6:Q46").Copy
' Paste the range
With PPPres.Slides(18).PasteSpecial
                .Top = 86.8969
                .Left = 19.98417
                .Height = 150.7964
                .Width = 600.5262
End With

But this does not work, and I was wondering if there is a way to do this. 但这不起作用,我想知道是否有办法做到这一点。 When I copy and paste I want to keep the formatting as well. 当我复制和粘贴时,我也想保留格式。

Addition 加成

I have done some research online and I have seen that if I want to keep the formatting of the range and don't want to copy the range as a picture then I need to use: 我已经在网上做了一些研究,我已经看到如果我想保持范围的格式并且不想将范围复制为图片,那么我需要使用:

ppapp.CommandBars.ExecuteMso ("PasteExcelTableSourceFormatting")

But I cannot get this to work this is what I am trying to do: 但我不能让这个工作,这是我想要做的:

    Sub CreatePP()
    Dim ppapp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim ppTextBox As PowerPoint.Shape
    Dim iLastRowReport As Integer
    Dim sh As Object
    Dim templatePath As String

Set ppapp = GetObject(, "PowerPoint.Application")

Set pptPres = PPApp.Presentations.Open("C:\Desktop\Template.pptx")
ppapp.Visible = True
Sheets("Tables").Select
Range("A27:D48").Copy

ppapp.ActivePresentation.Slides (5)
ppapp.CommandBars.ExecuteMso ("PasteExcelTableSourceFormatting")

Try pasting it as a EnhancedMetafile? 尝试将其粘贴为EnhancedMetafile?

Set myShapeRange = PPPres.Slides(18).PasteSpecial(ppPasteEnhancedMetafile)
With myShapeRange
            .Top = 86.8969
            .Left = 19.98417
            .Height = 150.7964
            .Width = 600.5262
End With

Function parameters via https://msdn.microsoft.com/en-us/library/office/ff745158.aspx 函数参数来自https://msdn.microsoft.com/en-us/library/office/ff745158.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM