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.
我正在尝试将一系列Excel表格放到PowerPoint中,并在2013年的Office中成功创建了一个宏,但我正在尝试将它改编为Office 2010。
The issue is when pasting the table to PowerPoint, Office 2010 seems to require a unique/different code.
问题是当将表粘贴到PowerPoint时,Office 2010似乎需要一个唯一的/不同的代码。
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:
但自那以后,我就被告知要使用2010年的版本。
'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.
这里使用的是DataType:=10将图表以不正确的格式放入PowerPoint中。我需要用ppPasteHTML把这个表格放到ppt中,但是,当我尝试将这个输入到pastspecial函数中时,我得到一个错误代码,说剪贴板是空的。
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?
有没有人知道“ppPasteHTML”是否有一个数字类型的数据类型,在过去的特殊情况下?或者用另一种方法把Excel表格变成Office 2010的表格?
Thanks!
谢谢!
2 个解决方案
#1
1
This should do it:
这应该这样做:
Just make sure you are loading the PowerPoint Library in Excel.
只要确保你在Excel中加载了PowerPoint库。
Tools->References->"Microsoft PowerPoint nn.n Object Library"
工具- >引用- >“微软PowerPoint nn。n对象库”
Also I assume that Table3
, ChartStart
, ChartEnd
& Row2
have set values
我还假设表3、ChartStart、ChartEnd和Row2都有设置值
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
0
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.
ppPasteHtml的长/数字等效项是8。您可以通过在PowerPoint中打开VBE,在直接窗口中执行ppPasteHTML或调试,来查询这个问题。在模块/例程中打印ppPasteHtml。
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.
另外,我见过一些其他问的人从一个应用程序有问题粘贴到另一个应用程序(例如,Excel和PowerPoint等)在这种情况下,似乎有时解决的唯一方法是使用CommandBars对象,但是我不确定如果有一个“HTML”从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:
这里有一些其他可能的MSO命令,你可以使用,但是就像我说的,我没有看到一个看起来会粘贴HTML,尽管这个列表是针对Office 2010的:
#1
1
This should do it:
这应该这样做:
Just make sure you are loading the PowerPoint Library in Excel.
只要确保你在Excel中加载了PowerPoint库。
Tools->References->"Microsoft PowerPoint nn.n Object Library"
工具- >引用- >“微软PowerPoint nn。n对象库”
Also I assume that Table3
, ChartStart
, ChartEnd
& Row2
have set values
我还假设表3、ChartStart、ChartEnd和Row2都有设置值
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
0
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.
ppPasteHtml的长/数字等效项是8。您可以通过在PowerPoint中打开VBE,在直接窗口中执行ppPasteHTML或调试,来查询这个问题。在模块/例程中打印ppPasteHtml。
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.
另外,我见过一些其他问的人从一个应用程序有问题粘贴到另一个应用程序(例如,Excel和PowerPoint等)在这种情况下,似乎有时解决的唯一方法是使用CommandBars对象,但是我不确定如果有一个“HTML”从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:
这里有一些其他可能的MSO命令,你可以使用,但是就像我说的,我没有看到一个看起来会粘贴HTML,尽管这个列表是针对Office 2010的: