PPT VBA记录

'删除ppt图片
Sub DeletePic()
    Dim mySlide As Slide
    Dim myShape As Shape, i_Temp As Integer
    On Error Resume Next
    
    For Each mySlide In ActivePresentation.Slides
        For Each myShape In mySlide.Shapes

            If myShape.Type = 13 Then
            
                'result = MsgBox(myShape.Type, vbOKCancel, "提示")
                
                'If result = vbCancel Then
                ' GoTo break
                'End If
            
                With myShape
                .Delete
                End With
            End If
        Next
    Next
    
break: MsgBox ("中止")
End Sub


'选中对象类型
Sub ShapeType()
    With ActiveWindow.Selection.ShapeRange(1)
        MsgBox (.Type)
    End With

End Sub
Sub PowerPointBasics_1() 
    ' PowerPoint 的对象模型 Ojbect Model (OM)模型导航 
    ' 每个东东在 PowerPoint 中都是某个类型的对象 
    ' 想操作好 PowerPoint,你就要和对象打交道 有些对象是另外一些对象的集合。 
    ' 对象具有属性 – 用来描述对象的东东 
    ' 对象具有方法 – 对象可以做或你可以对他做什么 
    ' 对象模型就是所有 PowerPoint 对象自成一个体系的集合 
    ' 就像一个倒置的树图 
     ' 按 F2 浏览查看对象 
     ' 数的最顶层是应用对象(Application) 
    ' 就是 PowerPoint 本身 
    ' 应用对象有他的属性 
    Debug.Print Application.Name 
     ' 用 Debug.Print 代替 MsgBox 能节省一点时间 
     ' 我们就不需要点击对话框的“确定”按钮 
     ' Debug.Print 的结果输出在 VB 编辑器环境中的立即窗口中 
     ' 如果它没有显示,通过点击菜单“视图”/“立即窗口”或者按 Ctrl+G 来显示 
     ' .Presentations 属性返回当前打开演示文档的一个集合 
     ' 我们通过“点”提示来调用它的功能 
     Debug.Print Application.Presentations.Count 
     ' 我们可以指定一个特定的对象 
    Debug.Print Application.Presentations(1).Name 
    ' 所以说 PowerPoint (即 application 对象) 包含 Presentations 对象 
    ' Presentations 包含 Slides 对象 
    ' Slides 包含 Shapes 对象,如 rectangles 和 circles。 
    ' 所以我们可以自然的这样写: 
    Debug.Print Application.ActivePresentation.Slides(2).Shapes.Count 
    ' 但是这么长的引用有些令人乏味 
    ' 另一种形式对我们来说更容易一些同时也会让 PowerPoint 处理的更快一些 
    ' 使用 With 关键字来引用你用的对象.. 
    With ActivePresentation.Slides(2).Shapes(2) 
        ' 这样你可以直接引用他的下级功能 
        Debug.Print .Name 
        Debug.Print .Height 
        Debug.Print .Width 
    ' 最后用 End With 关键字来表明引用完毕 
    End With 
    ' 我们也可以嵌套着使用 
    With ActivePresentation.Slides(2).Shapes(2) 
        Debug.Print .Name 
        With .TextFrame.TextRange 
            Debug.Print .Text 
            Debug.Print .Font.Name 
        End With 
    End With 
End Sub 
Sub PowerPointBasics_2() 
    ' 控制当前选中的对象 
    ' 显示对象的名字 
    With ActiveWindow.Selection.ShapeRange(1) 
        Debug.Print .Name 
    End With 
    ' 更改名字并移动他: 
    With ActiveWindow.Selection.ShapeRange(1) 
        ' 命名对象非常有用 
        .Name = "My favorite shape" 
        .Left = .Left + 72  ' 72 像素即 1 英寸 
    End With 
End Sub 
Sub PowerPointBasics_3() 
    ' 控制一个已命名的对象 
    ' 如果你知道一个对象的名字 
    ' 你就可以直接控制他 
    ' 不需要繁琐的调用了。 
    With ActivePresentation.Slides(2).Shapes("My favorite shape") 
        .Top = .Top - 72 
    End With 
    ' 每页幻灯片也可以有名字 
    With ActivePresentation.Slides(2) 
        .Name = "My favorite slide" 
    End With 
    ' 无论我们移动他到那个地方,名字不变 
    ' 这样我们就可以方便的操作啦 
    With ActivePresentation.Slides("My favorite slide").Shapes("My favorite shape") 
        .Height = .Height * 2 
    End With 
End Sub 
Sub PowerPointBasics_4() 
    ' 对象的引用 
    ' 可以通过变量来保持对对象的引用 
    ' 可能会有些难于理解,不过不用担心 
    ' 参照实例很容易理解的。 
    ' 先看下面的例子: 
    ' 定义一个变量为某个类型 
    Dim oShape As Shape 
    ' 让他指向某个特定的对象 
    Set oShape = ActivePresentation.Slides("My favorite slide").Shapes("My favorite shape") 
    ' 注意我们使用已命名的对象。 
    ' 从现在开始,我们就可以把 oShape 认作为我们命名的那个对象。 
    Debug.Print oShape.TextFrame.TextRange.Text 
    oShape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) 
    ' 直到我们删除这个变量,都可以认为他就是我们命名的那个对象。 
    Set oShape = Nothing 
End Sub 
Sub PowerPointBasics_5() 
    ' 遍历所有的幻灯片 
    ' 便利所有的对象 
    ' So far, we haven't done anything you couldn't do 
    ' with your mouse, and do it more easily at that. 
    ' One more little lesson, then the real fun starts. 
    Dim x As Long   ' we'll use X as a counter 
    ' OK, I said always to give variables meaningful names 
    ' But for little "throwaway" jobs like this, programmers often 
    ' use x, y, and the like 
    ' Let's do something with every slide in the presentation 
    For x = 1 To
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值