繁体   English   中英

将从Excel到Powerpoint的命名范围粘贴到命名形状-VBA

[英]Paste named range from Excel to Powerpoint into named shape - VBA

我想建立一个宏,将我们的Excel数据表与我们的Reporting-Powerpoint-Presentation连接起来。 因此,我选择并复制了这个名为Range(“ A”)的文件。 然后,我想将数据粘贴到Powerpoint中与我的Range(“ A”)同名的形状中。

Sub SyncWithPPT()

Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptShape As PowerPoint.Shape

Set pptApp = New PowerPoint.Application
pptApp.Visible = msoTrue
Set pptPres = pptApp.presentations.Open("workingPath")

ActiveWorkbook.Names("A").RefersToRange.Select
Selection.Copy
Set pptShape = pptPres.Slides("anySlide").Shapes("A")
pptShape.Table.cell(1, 1).Shape.TextFrame.TextRange.Paste 'Here it won't paste correctly

End Sub

除了粘贴之外,一切都很好。 当我粘贴选择内容时,所有内容都会粘贴到cell(1,1)中。
但是我想将每个单元复制到一个不同的单元中。 就像用STRG + V粘贴时一样。

任何帮助将非常感激。

这对我有用(Office 2007)...

Sub Tester()

    Dim ppt, sld

    'presentation is already open...
    Set ppt = GetObject(, "powerpoint.application")
    Set sld = ppt.activepresentation.slides(1)

    ActiveSheet.Range("A1:B2").Copy

    sld.Shapes(1).Table.Cell(1, 1).Select
    ppt.ActiveWindow.View.Paste

    Set sld = Nothing
    Set ppt = Nothing

End Sub
'this is how to extract each cell information
'assuming that ppt communication is already done.

Dim n As Integer, j As Integer
Dim ultimaFila As Long    

j = 1 'columna
ultimaFila = Range("A65536").End(xlUp).Row

For n = 1 To ultimaFila

   pptShape.Table.cell(n, j).Value = Application.Workbooks("Book1").Worksheets("Sheet1").Cells(n, j).Value        


Next n

End Sub

暂无
暂无

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

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