VB怎么打开PPT,然后对其进行一些操作?
1、VB打开用户自己的PPT 需要引用VB的PPT部件,而非Shell;
2、打开的PPT不可见,并自动运行一段可以自定义的VBA代码,实现某种操作;
3、代码运行完之后,自动关闭PPT ,全过程没有安全提示;
谢谢了.... 展开
因为,我用的是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 ‘退出。
dim ppt as new powerpoint.application
'需要执行的vba代码
'....
ppt.close
set ppt = nothing
哥们 能不能具体点..怎么打开PPT
还有那个VBA代码直接是模块可以吗?
dim ppt as new powerpoint.application
ppt.Presentations.Add WithWindow:=msoTrue
'对这个ppt操作的vba代码
'....
'保存
ppt.ActivePresentation.SaveAs FileName:="路径"
ppt.close
set ppt = nothing