Private Sub CommandButton1_Click()
TextBox1.Text = Int((6 * Rnd) + 1)
End Sub
窗没笑拍体上放一个按钮,引用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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)