VB怎么打开PPT,然后对其进行一些 *** 作?

VB怎么打开PPT,然后对其进行一些 *** 作?,第1张

窗没笑拍体上放一个按钮,引用Microsoft Powerpoint 11.0 Object Library,

因为,我用的是Office2003,可能你的是其他版本,那么这里的11可能是12或其他!

代码如下,复制了就能用,但是再次提醒,要做上升哗面的引用!

Option Explicit

Private Sub Command1_Click()

Dim pptApp As PowerPoint.Application

Dim MyPresentation As Presentation

Set pptApp = CreateObject("PowerPoint.Application") '创建PowerPoint对象实例

Set MyPresentation = pptApp.Presentations.Add(True) '设置幻灯片对象创建新的幻灯片

MyPresentation.Slides.Add 1, 12 '添加一页空白幻灯片

MyPresentation.Slides(1).Shapes.AddTextbox 1, 40, 160, 650, 50 '添加1个文本框

MyPresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text = "欢迎你使用VBA PowerPoint!" '在文本框里编辑文本

MyPresentation.Slides(1).Shapes(1).TextFrame.TextRange.Paragraphs(1).ParagraphFormat.Alignment = ppAlignCenter '设置文本框居中对齐

MyPresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Name = "宋体" '设置文本框字体

MyPresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Size = 40 '设置文本框枯羡字号

MyPresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Color.RGB = RGB(Red:=255, Green:=0, Blue:=0) '设置文本框文字颜色

MyPresentation.SaveAs ("c:\111.ppt") '保存到文件

MyPresentation.Close '关闭幻灯片

Set MyPresentation = Nothing '释放内存空间

pptApp.Quit '关闭PowerPoint

Set pptApp = Nothing '释放内存空间

End Sub

引用powerpoint

“Microsoft

Powerpoint

11.0

Object

Library”

前提是搭宴系统里安装了powerpoint2003

示例代码如下

Dim

op

As

PowerPoint.Presentation

Dim

moPptApp

As

PowerPoint.Application

Dim

moPptPresentation

As

Object

Dim

mnPptAppWidth

As

Single

'

Dim

mnPptAppheight

As

Single

'

Set

moPptApp

=

CreateObject("PowerPoint.Application")

Set

moPptPresentation

=

moPptApp.Presentations.Open(App.Path

&

"\test.ppt",

,

,

False)

‘打知码银开应用程序目录下的test.ppt文件

With

moPptPresentation.SlideShowSettings

.Run.Width

=

mnPptAppWidth

'设模颤置宽度

.Run.Height

=

mnPptAppheight

'设置高度

.Run.Presentation.DisplayComments

=

False

.Run.Presentation.Saved

=

True

'.Run

End

With

mopptapp.quit

‘退出。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12566303.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存