2012-08-29 130 views
0

我想要構建一個將我們的Excel-Data-Sheet與我們的Reporting-Powerpoint-Presentation連接起來的宏。 所以我選擇並複製了這個命名的範圍(「A」)。 然後,我想將數據粘貼到Powerpoint中與我的範圍(「A」)具有相同名稱的形狀中。將從Excel到Powerpoint的命名範圍粘貼到命名的形狀 - VBA

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時一樣。

任何幫助將非常感激。

+0

不幸的是我通過刪除我的大學老Dropbox帳戶失去了圖片。我刪除了這個問題中的鏈接,我認爲問題仍然很清楚。 – limfinity

+0

謝謝。我刪除了我的評論。 –

回答

1

這爲我工作(辦公室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 
+0

謝謝,就是這樣。 – limfinity

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