使用 VBA 将嵌入内容 (HTML) 的字体大小从 Excel 更改为 Powerpoint

Using VBA to change the font size of embedded content (HTML) from Excel to Powerpoint

我正在尝试编写代码以将 Excel 工作表中的内容复制到 Powerpoint(我对编程一无所知,并且在谷歌上搜索了所有内容 - 我的代码可能一团糟)。我设法将内容复制到 Powerpoint 并将其作为 HTML 嵌入其中(因为我希望能够在复制后在 Powerpoint 中编辑复制的数据),代码如下:

Sub ExportContent()

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(1)

'open ppt
Set PPTApp = CreateObject("PowerPoint.Application")
PPTApp.Visible = msoTrue
Set pptPres = PPTApp.Presentations.Add(msoTrue)
Set pptslide = pptPres.Slides.Add(Index:=1, Layout:=12)

'copy Excel content
Set rng = ws.Range("A1:G50")
rng.Copy

'copy to ppt
pptslide.Shapes.PasteSpecial DataType:=8
Set excontent = pptslide.Shapes(pptslide.Shapes.Count)

'change font
With excontent.Shapes(1).TextFrame.TextRange.Characters
  .Font.Size = 30
End With

但是,我正在努力使用 Excel VBA 更改复制内容的字体大小的代码。在 Powerpoint 中,您可以 select 所有内容并点击字体大小旁边的向上小箭头以增加 所有内容 的字体大小。所以我的问题是:

  1. 是否可以使用 Excel VBA 来做到这一点?
  2. 如果是,怎么做?我已经尝试过之前在网上找到的解决方案(例如),但我总是编译错误。

非常感谢您的帮助!

Sub ExportContent()
' two new variables:
Dim lCol As Long
Dim lRow As Long
' And if you're not already doing so outside this snippet
' you should be declaring ALL of your variables
' Add OPTION EXPLICIT to the top of every module. 
' It'll keep you honest.

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(1)

'open ppt
Set PPTApp = CreateObject("PowerPoint.Application")
PPTApp.Visible = msoTrue
Set pptPres = PPTApp.Presentations.Add(msoTrue)
Set pptslide = pptPres.Slides.Add(Index:=1, Layout:=12)

'copy Excel content
Set rng = ws.Range("A1:G50")
rng.Copy

'copy to ppt
pptslide.Shapes.PasteSpecial DataType:=8
Set excontent = pptslide.Shapes(pptslide.Shapes.Count)

'change font
' The pasted HTML will come into PPT as a table, 
' so you need to treat it as such:
    With excontent.Table
        For lCol = 1 To .Columns.Count
            For lRow = 1 To .Rows.Count
                .Cell(lRow, lCol).Shape.TextFrame.TextRange.Font.Name = "Algerian"
                ' do whatever formatting to the text you want to do here
                ' or work with .Cell(lRow, lCol).Shape to change cell fills etc
            Next
        Next
    End With