保持从Excel到Powerpoint的字体格式

时间:2017-02-01 21:54:12

标签: excel vba excel-vba powerpoint-vba

我有一个VBA宏,可以将Excel中的图表粘贴到PowerPoint中,这样就可以了。

我已调整宏以将同一工作表的某些单元格的单元格内容复制到PowerPoint中。尽管在宏复制它之前将Excel中的字体大小设置为与PowerPoint模板中相同(尽管两者都是40点),但字体会粘贴在18点而不是40,这是我在宏运行之前在Excel中设置的

处理所有这些的代码如下:

'Opens a new PowerPoint presentation based on template and pastes data into Slide 2 of Powerpoint from Excel

Dim PPApp As PowerPoint.Application, PPPres As PowerPoint.Presentation, PPSlide As PowerPoint.Slide, PPShape As Object, PPChart As Object

Dim XLws As Worksheet

Set XLws = ActiveSheet
Set PPApp = New PowerPoint.Application
Set PPPres = PPApp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Monthly Report Template Macro.potm", Untitled:=msoTrue)
PPApp.Visible = True
Set PPSlide = PPPres.Slides(12)

XLws.ChartObjects(1).Copy ' or XLws.ChartObjects("Chart 2").Copy
Set PPChart = PPSlide.Shapes.PasteSpecial(DataType:=ppPasteDefault)

With PPChart

.Left = 18
.Height = 322
.Top = 121
.Width = 531

End With

'Copies Contents of Cells Q36 and R36 in excel worksheet and pastes as text into slide 13 of presentation
  XLws.Range("Q36:R36").Copy
  Set PPChart = PPSlide.Shapes.PasteSpecial(DataType:=ppPasteDefault)

Set PPSlide = PPPres.Slides(13)

1 个答案:

答案 0 :(得分:0)

科林,

复制后是否要更改字体大小?也许它会自动链接/更新。

如果您可以使用其中一个粘贴选项手动复制它,我建议使用以下帖子中引用的ExecuteMso命令来更准确地模仿您正在做的事情:

How to copy a chart from Excel to PowerPoint?