0

我想构建一个宏,将我们的 Excel-Data-Sheet 与 Reporting-Powerpoint-Presentation 连接起来。所以我选择并复制了这个命名范围(“A”)。然后我想将数据粘贴到 Powerpoint 中与我的范围(“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

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

任何帮助将非常感激。

4

2 回答 2

1

这对我有用(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
于 2012-08-29T22:39:12.220 回答
0
'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
于 2012-08-30T00:21:08.670 回答