问题
I'm trying to get a series of Excel tables into PowerPoint and successfully created a macro for this in Office 2013, but am trying to adapt it to Office 2010.
The issue is when pasting the table to PowerPoint, Office 2010 seems to require a unique/different code.
Originally I had:
'Copying Tables to PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
For i = 0 To Table3
Sheets("Charts").Range(ChartStart, ChartEnd).Offset(i * Row2, 0).Copy
Set PPSlide = PPPres.Slides(1)
Set PPShape = PPSlide.Shapes.Paste
PPShape.Name = "Table" & i
But have since been informed a fix for 2010 versions is to use .PasteSpecial so I have:
'Copying Tables to PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
For i = 0 To Table3
Sheets("Charts").Range(ChartStart, ChartEnd).Offset(i * Row2, 0).Copy
Set PPSlide = PPPres.Slides(1)
Set PPShape = PPSlide.Shapes.PasteSpecial(dataType:=10)
PPShape.Name = "Table" & i
The thing is using DataType:=10 puts the chart into PowerPoint in an incorrect format for my purposes. I need to get the table into PowerPoint as a table using ppPasteHTML, however, when I try to enter this into the PasteSpecial function I get an error code saying the Clip board is empty.
Does anyone know if "ppPasteHTML' has a numeric equivalent for the DataType option in PasteSpecial? Or another way to get an Excel table into PowerPoint as a table for Office 2010?
Thanks!
回答1:
This should do it:
Just make sure you are loading the PowerPoint Library in Excel.
Tools->References->"Microsoft PowerPoint nn.n Object Library"
Also I assume that Table3
, ChartStart
, ChartEnd
& Row2
have set values
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
'Open PowerPoint and create a new presentation.
Set pptApp = New PowerPoint.Application
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
For i = 0 To Table3
Set objRange = Worksheets("Charts").Range(ChartStart, ChartEnd).Offset(i * Row2, 0)
objRange.Copy
pptSlide.Shapes.PasteSpecial DataType:=ppPasteHTML, Link:=msoFalse
Next i
For j = 1 To pptSlide.Shapes.Count
With pptSlide.Shapes(j)
.Name = "Table" & j
End With
Next j
Set pptSlide = Nothing
Set pptPres = Nothing
Set pptApp = Nothing
回答2:
The long/numeric equivalent for ppPasteHtml
is 8
. You can query this for yourself by opening up the VBE in PowerPoint, and doing ?ppPasteHTML
in the Immediate window, or Debug.Print ppPasteHtml
in a module/routine.
Using early binding, try:
pptSlide.Shapes.PasteSpecialy DataType:=ppPasteHtml
Or, using late binding:
pptSlide.Shapes.PasteSpecial DataType:=8
Alternatively, I have seen a few other q's where people have problems pasting from one application to another application (e.g., from Excel to PowerPoint etc.) In those cases, it seems that sometimes the only way to resolve is to use the CommandBars
object, however I am not sure if there is an "HTML" paste method from CommandBars.
pptSlide.Parent.ExecuteMso "PasteExcelTableSourceFormatting"
Here are some other possible MSO commands you could use, but like I said I don't see one that appears to paste HTML, although this list is for Office 2010:

来源:https://stackoverflow.com/questions/25558354/best-way-to-copy-excel-table-into-powerpoint-2010