VBA第三十九期 VBA自动把工作表转换成PPT

发布于:2025-04-09 ⋅ 阅读:(23) ⋅ 点赞:(0)

和前面两节一样运行Microwof PowerPoint时需要对其对象库进行引用,在Excel中打开VBE,选择“工具”,激活“引用”对话框后,通过滚动条找到 Microsoft PowerPoint XX Object Library,选中该项。具体操作步骤参照前面章节。

Sub SendiMorkbookToPowerPoint ()

peclare your variables

Dim pp As PowerPoint. Application

Dim PPPres As PowerPoint. Presentation

Dim PPSlide As PowerPoint. Slide

Dim xlwksht As Excel. Worksheet

Dim MyRange As String

Dim MyTitle As String

Powerpoint,add a new presentation and make visible

Set pp= New PowerPoint. Application

Set PPPres = pp. Presentations. Add

pp. Visible= True

MyRange="A1: I00"

For Each xlwksht In ActiveWorkbook. Worksheets

xlwksht. Select

Application. Wait (Now+TimeValue("0:00:2”))

MyTitle=xlwksht. Range ("C10") . Value

xlwksht. Range (MyRange) . CopyPictureAppearance: =x1Screen, Format: =x1Picture

slideCount=PPPres. Slides. Count

Set PPSlide= PPPres. Slides. Add (S1ideCount +1, ppLayoutTitleonly)

PPSlide. Select

PPSlide. Shapes. Paste. Select

pp. ActiveWindo. Selection. ShapeRange. Align msoAlignCenters, True

pp. ActiveWindow. Selection. ShapeRange. Top=50

PPSlide. Shapes. Title. TextFrame. TextRange. Text = MyTitle

Next

‘恢复初始设置,这个是不能省略的,虽然省略程序依然可以运行

pp. Activate

Set PPSlide = Nothing

Set PPPres=Nothing

Set pp=Nothing

End Sub