使用给定的字体和字体颜色将Excel范围粘贴到PowerPoint表

时间:2016-10-14 13:01:09

标签: excel vba excel-vba powerpoint powerpoint-vba

我按照此示例将Excel范围粘贴到PowerPoint表格中:

Dim oPPTApp As PowerPoint.Application
Dim oPPTShape As PowerPoint.Shape
Dim oPPTFile As PowerPoint.Presentation
Dim SlideNum As Integer

Sub PPTableMacro()

Dim strPresPath As String, strExcelFilePath As String, strNewPresPath As String
strPresPath = "H:\PowerPoint\Presentation1.ppt"
strNewPresPath = "H:\PowerPoint\new1.ppt"

Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table1")

Sheets("Sheet1").Activate
oPPTShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = Cells(1, 1).Text
oPPTShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2).Text
oPPTShape.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1, 3).Text
oPPTShape.Table.Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2, 1).Text
oPPTShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2, 2).Text
oPPTShape.Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2, 3).Text

oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit

Set oPPTShape = Nothing
Set oPPTFile = Nothing
Set oPPTApp = Nothing

MsgBox "Presentation Created", vbOKOnly + vbInformation
End Sub

这很好,但我的问题是,我想粘贴Excel中使用的font-color和fon-类型。无法找到一种方法来完成这项工作。我尝试使用“PasteSpecial”,但似乎没有任何工作,因为我想直接粘贴到给定的PowerPoint表。

有人有个主意吗?

例如,如果我在Excel工作表中手工复制彩色数字,直接将它们粘贴到PowerPoint表格中,则可以保留格式。但是因为我无法在PP中记录宏,并且无法找到如何做到这一点。

0 个答案:

没有答案