[英]Copy range from Excel sheet to table in PowerPoint using VBA
I tried this code for copying a range from an Excel sheet to a table in PowerPoint but it was not run.我尝试使用此代码将范围从 Excel 工作表复制到 PowerPoint 中的表格,但未运行。
ppapp.Visible = True
For Each sh In ThisWorkbook.Sheets
If sh.Name Like "E_KRI" Then ppapp.ActivePresentation.Slides.Add
ppapp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
ppapp.ActiveWindow.View.GotoSlide
ppapp.ActivePresentation.Slides.Count Set ppSlide =
ppapp.ActivePresentation.Slides(ppapp.ActivePresentation.Slides.Count)
ppSlide.Select
iLastRowReport = Range("B" & Rows.Count).End(xlUp).Row
Range("A3:J" & iLastRowReport).Copy
Set tbl = ppapp.ActiveWindow.Selection.ShapeRange.Table
tbl.Cell(5,3).Shape.paste
I have the following code:我有以下代码:
Paste into exisiting table using either the PowerPoint Table format, or the Excel Range format.使用 PowerPoint 表格格式或 Excel 范围格式粘贴到现有表格中。
Public Sub ExcelRange_to_PPT_Table() Dim ppApp As PowerPoint.Application Dim ppPres As PowerPoint.Presentation Dim ppTbl As PowerPoint.Shape On Error Resume Next Set ppApp = GetObject(, "PowerPoint.Application") On Error GoTo 0 If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application Set ppPres = ppApp.Presentations.Item(1) Else Set ppPres = ppApp.Presentations.Item(1) End If ppApp.ActivePresentation.Slides(1).Select ppPres.Windows(1).Activate ' find on Slide Number 1 which object ID is of Table type (you can change to whatever slide number you have your table) With ppApp.ActivePresentation.Slides(1).Shapes For i = 1 To .count If .Item(i).HasTable Then ShapeNum = i End If Next End With ' assign Slide Table object Set ppTbl = ppApp.ActivePresentation.Slides(1).Shapes(ShapeNum) ' copy range from Excel sheet iLastRowReport = Range("B" & Rows.count).End(xlUp).row Range("A3:J" & iLastRowReport).Copy ' select the Table cell you want to copy to >> modify according to the cell you want to use as the first Cell ppTbl.Table.Cell(3, 1).Shape.Select ' paste into existing PowerPoint table - use this line if you want to use the PowerPoint table format ppApp.CommandBars.ExecuteMso ("PasteExcelTableDestinationTableStyle") ' paste into existing PowerPoint table - use this line if you want to use the Excel Range format ' ppApp.CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting") End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.