来源:http://support.microsoft.com/kb/222929

通过使用 PowerPoint 中的自动运行功能,您可以以编程方式打印、显示幻灯片及执行以交互式执行的大多数事情。按照以下步骤构建并运行一个 Visual Basic 自动运行示例:

  1. 创建一个新的标准 EXE 项目。Form1 是默认创建的窗体。
  2. 向默认的窗体添加一个 CommandButton。
  3. 项目菜单上,单击引用,添加 Microsoft PowerPoint 8.0 对象库Microsoft Office 8.0 对象库。对于 Office 2000,类型库的版本是 9.0。对于 Office 2002,类型库的版本是 10.0。对于 Microsoft Office 2003,类型库的版本是 11.0。
  4. 将以下代码添加到您的窗体代码窗口中:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Sub Command1_Click()
    ' Start PowerPoint.
    Dim ppApp As PowerPoint.Application
    Set ppApp = CreateObject("Powerpoint.Application") ' Make it visible.
    ppApp.Visible = True ' Add a new presentation.
    Dim ppPres As PowerPoint.Presentation
    Set ppPres = ppApp.Presentations.Add(msoTrue) ' Add a new slide.
    Dim ppSlide1 As PowerPoint.Slide
    Set ppSlide1 = ppPres.Slides.Add(1, ppLayoutText) ' Add some text.
    ppSlide1.Shapes(1).TextFrame.TextRange.Text = "My first slide"
    ppSlide1.Shapes(2).TextFrame.TextRange.Text = "Automating Powerpoint is easy" & vbCr & "Using Visual Basic is fun!" ' Add another slide, with a chart.
    Dim ppSlide2 As PowerPoint.Slide
    Set ppSlide2 = ppPres.Slides.Add(2, ppLayoutTextAndChart) ' Add some text.
    ppSlide2.Shapes(1).TextFrame.TextRange.Text = "Slide 2's topic"
    ppSlide2.Shapes(2).TextFrame.TextRange.Text = "You can create and use charts in your Powerpoint slides!" ' Add a chart in the same location as the old one.
    Dim cTop As Double
    Dim cWidth As Double
    Dim cHeight As Double
    Dim cLeft As Double
    With ppSlide2.Shapes(3)
    cTop = .Top
    cWidth = .Width
    cHeight = .Height
    cLeft = .Left
    .Delete
    End With
    ppSlide2.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "MSGraph.Chart" ' Add another slide, with an organization chart.
    Dim ppSlide3 As PowerPoint.Slide
    Set ppSlide3 = ppPres.Slides.Add(3, ppLayoutOrgchart) ' Add some text. ppSlide3.Shapes(1).TextFrame.TextRange.Text = "The rest is only limited by your Imagination" ' Add an Org Chart in the same location as the old one.
    With ppSlide3.Shapes(2)
    cTop = .Top
    cWidth = .Width
    cHeight = .Height
    cLeft = .Left
    .Delete
    End With
    ppSlide3.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "OrgPlusWOPX.4" 'OrgPlusWOPX.4
    ' is an object of the application Microsoft Organization Chart ' Setup slide show properties.
    With ppPres.Slides.Range.SlideShowTransition
    .EntryEffect = ppEffectRandom
    .AdvanceOnTime = msoTrue
    .AdvanceTime = 5 ' 5 seconds per slide
    End With ' Prepare and run the slide show.
    With ppPres.SlideShowSettings
    .ShowType = ppShowTypeKiosk
    .LoopUntilStopped = msoTrue .RangeType = ppShowAll
    .AdvanceMode = ppSlideShowUseSlideTimings
    .Run
    End With ' Sleep so user can watch the show.
    Sleep (15000) ' Clean up.
    ppApp.Quit End Sub
  5. 运行该项目。

vb 运行ppt示例代码的更多相关文章

  1. 《ArcGIS Runtime SDK for Android开发笔记》——(7)、示例代码arcgis-runtime-samples-android的使用

    1.前言 学习ArcGIS Runtime SDK开发,其实最推荐的学习方式是直接看官方的教程.示例代码和帮助文档,因为官方的示例一般来说都是目前技术最新,也是最详尽的.对于ArcGIS Runtim ...

  2. 用Java为Hyperledger Fabric(超级账本)开发区块链智能合约链代码之部署与运行示例代码

    部署并运行 Java 链代码示例 您已经定义并启动了本地区块链网络,而且已构建 Java shim 客户端 JAR 并安装到本地 Maven 存储库中,现在已准备好在之前下载的 Hyperledger ...

  3. SkylineGlobe 支持火狐和谷歌浏览器的可运行示例代码

    示例代码: <html> <head> <title>3dml的Feature对象选中和隐藏</title> <script type=" ...

  4. [转] VS2015中跑OpenGL红宝书第八版的第一章示例代码,运行

    Ori Article Link OpenGL的东西快忘光了,把角落的第八版红宝书拿出来复习一下 从书中的地址下了个示例代码结果新系统(Win10+VS2015)各种跑不起来,懊恼之后在网上疯狂搜索资 ...

  5. python开源项目及示例代码

    本页面是俺收集的各种 Python 资源,不定期更新. 下面列出的各种 Python 库/模块/工具,如果名称带超链接,说明是第三方的:否则是 Python 语言内置的. 1 算法 1.1 字符串处理 ...

  6. python开源项目及示例代码(转)

    本页面是俺收集的各种 Python 资源,不定期更新. 下面列出的各种 Python 库/模块/工具,如果名称带超链接,说明是第三方的:否则是 Python 语言内置的. 1 算法 1.1 字符串处理 ...

  7. 编译opengl编程指南第八版示例代码通过

    最近在编译opengl编程指南第八版的示例代码,如下 #include <iostream> #include "vgl.h" #include "LoadS ...

  8. 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

  9. 【译】用Fragment创建动态的界面布局(附Android示例代码)

    原文链接:Building a Dynamic UI with Fragments 为了在Android上创建一个动态和多视图的用户界面,你需要封装UI控件和模块化Activity的行为,以便于你能够 ...

随机推荐

  1. Kafka详解与总结(六)

    索引 稀疏存储,每隔一定字节的数据建立一条索引(这样的目的是为了减少索引文件的大小). 下图为一个partition的索引示意图: 注: 现在对6.和8建立了索引,如果要查找7,则会先查找到8然后,再 ...

  2. java 序列化和反序列化数据

    使用ObjectOutputStream 序列号原始数据和对象数据,使用ObjectInputStream 反序列化 使用字节存储数据,可以将序列化的数据存储到硬盘上,或输出到网络上 package ...

  3. POJ 2773 欧几里得

    思路: 若a和b互素的话,则b*t+a和b一定互素 用周期性做就好了 //By SiriusRen #include <cstdio> using namespace std; ],m,k ...

  4. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...

  5. T-SQL编程以及常用函数

    1.索引添加索引,设计界面,在任何一列前右键--索引/键--点击进入添加某一列为索引 2.视图 视图就是我们查询出来的虚拟表创建视图:create view 视图名 as SQL查询语句,分组,排序, ...

  6. ASP.NET中的<%%>介绍

    一.主要用于ASP.NET前台绑定用的最多: <%#Eval("")%> <%#Bind("")%> <%=变量%> 1.& ...

  7. (二)Mybatis总结之通过Dao层与数据交互

    Mybatis概述 定义: Mybatis是一个支持普通sql查询,存储过程和高级映射的优秀持久层框架. Mybatis是(半自动的)跟数据库打交道的orm(object relationship m ...

  8. 06使用NanoPiM1Plus在Android4.4.2下接U盘

    06使用NanoPiM1Plus在Android4.4.2下接U盘 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/5 17:51 版本:V ...

  9. error C2143: syntax error : missing ';' before '}'

    今天弄Tab控件,干了一件非常愚蠢的事,没有去声明头文件.这也是今天要记录的问题,提示如下各种 前面一个符号是错误的.如果初学者遇到,算作一个提示,记得声明新类的.h 头文件 标签空间再进一步.cpp ...

  10. HDU_2844_(多重背包)

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...