该对象代表 PowerPoint 应用程序,通过该对象可访问PowerPoint 中的其他所有对象。 (1)Active 属性:返回指定窗格是否被激活。
(2)ActivePresentation 属性:返回Presentation 对象,代表活动窗口中打开的演示文稿。 (3)ActiveWindow 属性:返回DocumentWindow 对象,代表当前文档窗口。 (4)Presentations 属性:返回Presentations **,代表所有打开的演示文稿。
(5)SlideShowWindows 属性:返回 SlideShowWindows **,代表所有打开的幻灯片放映窗 口。
(6)Quit 方法:用于退出PowerPoint 程序。 2.DocumentWindow 对象
该对象代表文档窗口。使用“Windows(index) ”语法可返回DocumentWindow 对象。 (1)ActivePane 属性:返回Pane 对象,代表文档窗口中的活动窗格。 (2)Panes 属性:返回Panes **,代表文档窗口中的所有窗格。 (3)ViewType 属性:返回指定的文档窗口内的视图类型。[NextPage] 3.Presentation 对象
该对象代表演示文稿,通过“Presentations(index)”语法可返回Presentation 对象。 (1)BuiltInDocumentProperties 属性:返回DocumentProperties **,代表演示文稿的所有文 档属性。
(2)ColorSchemes 属性:返回ColorSchemes **,代表演示文稿的配色方案。
(3)PageSetup 属性:返回PageSetup 对象,用于控制演示文稿的幻灯片页面设置属性。 (4)SlideMaster 属性:返回幻灯片母版对象。
(5)SlideShowSettings 属性:返回SlideShowSettings 对象,代表演示文稿的幻灯片放映设置。
(6)SlideShowWindow 属性:返回幻灯片放映窗口对象。 (7)AddTitleMaster 方法:为演示文稿添加标题母版。 (8)ApplyTemplate 方法:对演示文稿应用设计模板。 4.SlideShowWindow 对象 该对象代表幻灯片放映窗口。
IsFullScreen 属性:用于设置是否全屏显示幻灯片放映窗口。[NextPage] 5.Master 对象
该对象代表幻灯片母版、标题母版、讲义母版或备注母版。
TextStyles 属性:为幻灯片母版返回TextStyles **,代表标题文本、正文文本和默认文本。 6.Slide 对象 该对象代表幻灯片。
(1)SlideID 属性:返回幻灯片的唯一标识符。
(2)SlideIndex 属性:返回幻灯片在Slides **中的索引号。 7.SlideShowView 对象
该对象代表幻灯片放映窗口中的视图。
(1)AcceleratorsEnabled 属性:用于设置是否允许在幻灯片放映时使用快捷键。 (2)CurrentShowPosition 属性:返回当前幻灯片在放映中的位置。 (3)DrawLine 方法:在指定幻灯片放映视图中绘制直线。
(4)EraseDrawing 方法:用于清除通过DrawLine 方法或绘图笔工具在放映中绘制的直线。
(5)GotoSlide 方法:用于切换指定幻灯片。[NextPage]
2011-11-24 20:04 回复
t1181 4位粉丝
中级粉丝
2
44楼
Sub Power
PointBasics_1() ' PowerPoint 的对象模型 Ojbect Model (OM) '模型导航
' 每个东东在PowerPoint 中都是某个类型的对象 ' 想操作好PowerPoint,你就要和对象打交道 ' 有些对象是另外一些对象的**。 ' 对象具有属性 – 用来描述对象的东东
' 对象具有方法 – 对象可以做或你可以对他做什么 ' 对象模型就是所有PowerPoint 对象自成一个体系的** ' 就像一个倒置的树图 ' 按 F2 浏览查看对象 ' 数的最
顶层是应用对象(Application) ' 就是PowerPoint 本身 ' 应用对象有他的属性 Debug.Print Application.Name ' 用Debug.Print 代替 MsgBox 能节省一点时间 ' 我
们就不需要点击对话框的“确定”按钮 ' Debug.Print 的结果输出在VB 编辑器环境中的立即窗口中 ' 如果它没有显示,通过点击菜单“视图”/“立即窗口”或者按C
trl+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.Co
unt ' 但是这么长的引用有些令人乏味 ' 另一种形式对我们来说更容易一些同时也会让PowerPoint 处理的更快一些 ' 使用With 关键字来引用你用的对象.. With Act
ivePresentation.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 .Te
xt Debug.Print .Font.Name End With End With End Sub Sub PowerPointBasics_2() ' 控制当前选中的对象 ' 显示对象的名字 With ActiveWindow.Sele
2011-11-24 20:05 回复
t1181
4位粉丝
中级粉丝
2
ction.ShapeRange(1) Debug.Print .Name End With '
45楼
更改名字并移动他:
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\" 2011-11-24 20:06 回复
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
46楼
Sub PowerPointBasics_5() ' 遍历所有的幻灯片 ' 便利所有的对象
t1181
4位粉丝
中级粉丝2
' 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 ActivePresentation.Slides.Count Debug.Print ActivePresentation.Slides(x).Name Next x
' Or with every shape on one of the slides
' Since x is a \"junk\" variable, we'll just re-use it here ' And we'll use the With syntax to save some typing With ActivePresentation.Slides(3) For x = 1 To .Shapes.Count Debug.Print .Shapes(x).Name Next x
End With ' ActivePresentation.Slides(3) End Sub
Sub PowerPointBasics_6() ' 处理异常错误
' You can trust computer users to do one thing and one thing only: ' The Unexpected
' You can trust computers to do pretty much the same ' That's where error handling comes in
' What do you think will happen when I run this code? With ActivePresentation.Slides(42)
MsgBox (\"Steve, you moron, there IS no slide 42!\") End With End Sub
Sub PowerPointBasics_6a() ' Error Handling Continued
' Let's protect our code against boneheaded Steves ' If he does something that provokes an error, deal with it gracefully
On Error GoTo ErrorHandler With ActivePresentation.Slides(42)
MsgBox (\"Steve, you moron, there IS no slide 42!\") End With
' Words with a : at the end are \"labels\"
' and can be the destination of a \"GoTo\" command ' Using GoTo is considered Very Bad Form except in error handlers
' If we got here without error we need to quit before we hit the error
' handling code so ... NormalExit: Exit Sub ErrorHandler:
MsgBox (\"Error: \" & Err.Number & vbCrLf & Err.Description) ' resume next ' exit sub
Resume NormalExit End Sub Option Explicit
Public strText As String Public strOption As String Sub Forms_1()
' Creating/Showing/Unloading a form
' Forms are a more sophisticated way of getting user input than
' simple InputBox commands ' For example: frmMyForm1.Show
' now the user has dismissed the form ' let's see what they entered
Debug.Print frmMyForm1.TextBox1.Text
If frmMyForm1.OptionButton1.Value = True Then Debug.Print \"Yes\" End If
If frmMyForm1.OptionButton2.Value = True Then Debug.Print \"Chocolate\" End If
If frmMyForm1.OptionButton3.Value = True Then Debug.Print \"Teal\" End If
' we're done with the form so unload it Unload frmMyForm1
' But what if we want to make the form data available until much later?
' And wouldn't it make more sense to keep all the for***ogic
' in the form itself? End Sub Sub Forms_2()
' This uses a form with the logic built in
' Note that we had to declare a few PUBLIC variables ' so the form could get at them frmMyForm2.Show
' we're done with the form so unload it Unload frmMyForm2
' let's see what they entered - our variables still have the values
' the form code assigned them: Debug.Print strText Debug.Print strOption ' CODE RE-USE
' We can export the form to a file and import it into other projects End Sub
This is the code from the Animation Tricks section of the seminar (modAnimationTricks) Option Explicit
' This tells VBA how to call on the Windows API Sleep function
2011-11-24 20:07 回复
' This function puts our VBA code to sleep for X milliseconds
' (thousandths of a second) then lets it wake up after that ' Unlike other ways of killing time, this doesn't hog computer cycles
Private Declare Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)
Sub xYouClicked(oSh As Shape) Dim oShThought As Shape
Set oShThought = oSh.Parent.Shapes(\"Thought\") ' Make the thought balloon visible oShThought.Visible = True
' Move it to just to the right of the clicked shape oShThought.Left = oSh.Left + oSh.Width
' Position it vertically just above the clicked shape oShThought.Top = oSh.Top - oShThought.Height Select Case UCase(oSh.Name) Case Is = \"EENIE\"
oShThought.TextFrame.TextRange.Text = \"Pest!\" Case Is = \"MEENIE\"
oShThought.TextFrame.TextRange.Text = \"This is annoying!\"
Case Is = \"MINIE\"
oShThought.TextFrame.TextRange.Text = \"This is REALLY annoying!!\" Case Is = \"MOE\"
oShThought.Visible = False
oSh.Parent.Shapes(\"STOP\").Visible = True End Select End Sub
47楼
Sub yYouClicked(oSh As Shape)
t1181
4位粉丝
中级粉丝
2
' This time we'll use tags to make it easier to maintain Dim oShThought As Shape
Set oShThought = oSh.Parent.Shapes(\"Thought\")
' Make the thought balloon visible and move it next to the ' shape the user just clicked oShThought.Visible = True
oShThought.Left = oSh.Left + oSh.Width oShThought.Top = oSh.Top - oShThought.Height ' Use tags to pick up the text
oShThought.TextFrame.TextRange.Text = oSh.Tags(\"Thought\") End Sub Sub AddATag()
' A little macro to add a tag to the selected shape Dim strTag As String
' Our old buddy InputBox gets the tag text ...
strTag = InputBox(\"Type the text for the thought balloon\\"What is the shape thinking?\")
' Instead of forcing user to enter something, we'll just quit ' if not
If strTag = \"\" Then Exit Sub End If
' Must have entered something, so tag the shape with it With ActiveWindow.Selection.ShapeRange(1) .Tags.Add \"Thought\strTag End With End Sub
Sub YouClicked(oSh As Shape)
' And now we'll add a WinAPI Sleep call to make it even smoother
Dim oShThought As Shape
Set oShThought = oSh.Parent.Shapes(\"Thought\") ' Use tags to pick up the text
oShThought.TextFrame.TextRange.Text = oSh.Tags(\"Thought\") ' Make the thought balloon visible and move it next to the
' shape the user just clicked
oShThought.Left = oSh.Left + oSh.Width 2011-11-24 20:07 回复
t1181
4位粉丝
中级粉丝
2
oShThought.Top = oSh.Top - oShThought.Height oShThought.Visible = True
' give the system a little time to redraw DoEvents
' Now wait a second (1000 milliseconds to be precise) ... Sleep 1000
' and make it invisible again oShThought.Visible = False End Sub Sub Reset()
' Re-bait our little trap so it's ready for the next ' unwary user
ActivePresentation.Slides(\"AnimationTricks\").Shapes(\"STOP\").Visible = False
ActivePresentation.Slides(\"AnimationTricks\").Shapes(\"Thought\").Visible = False End Sub
48楼
PPT学习讲义
ActivePresentation.Slides(2).Shapes.Placeholders(1).Delete
ActivePresentation.Save
ActivePresentation.NewWindow
创建ppt文档。增加一张slide
With Presentations.Add
.Slides.Add Index:=1, Layout:=ppLayoutTitle
.SaveAs \"Sample\"
End With
打开ppt文档。
Presentations.Open FileName:=\"c:\\My Documents\\pres1.ppt\_
ReadOnly:=msoTrue
创建保存ppt
Sub AddAndSave(pptPres As Presentation)
pptPres.Slides.Add 1, 1
pptPres.SaveAs pptPres.Application.Path & \"\\Added Slide\" End Sub
Slide标题删除与恢复
ActivePresentation.Slides(2).Shapes.Placeholders(1).Delete
Application.ActivePresentation.Slides(2) _
.Shapes.AddPlaceholder ppPlaceholderTitle
当前演示文稿中添加一张幻灯片,为该幻灯片标题(幻灯片第一个占位符)和副标题添加文本
Set myDocument = ActivePresentation.Slides(1)
With ActivePresentation.Slides _
.Add(1, ppLayoutTitle).Shapes.Placeholders
.Item(1).TextFrame.TextRange.Text = \"This is the title text\"
.Item(2).TextFrame.TextRange.Text = \"This is subtitle text\"
End With
将主题或设计模式应用于当前ppt
ActivePresentation.ApplyTheme
若要在幻灯片中添加形状并返回一个代表新建形状的 Shape 对象,请使用 Shapes **的下列方法之一:AddCallout 、AddComment 、AddConnector 、AddCurve 、AddLabel 、AddLine 、AddMediaObject 、AddOLEObject 、AddPicture 、AddPlaceholder 、AddPolyline 、AddShape 、AddTable 、AddTextbox 、AddTextEffect 、AddTitle 。
使用 Shapes.Title 返回代表幻灯片标题的 Shape 对象。使用 Shapes.AddTitle 在无标题的幻灯片中添加标题并返回代表新建标题的 Shape 对象。
使用Shapes.Placeholders(index) 返回一个代表占位符的 Shape 对象,其中 index 是占位符的索引号。
如果没有改变过幻灯片中形状的排列顺序,则以下三个语句是等价的(假设第一张幻灯片有标题)。
ActivePresentation.Slides(1).Shapes.Title _
.TextFrame.TextRange.Font.Italic = True
ActivePresentation.Slides(1).Shapes.Placeholders(1) _
.TextFrame.TextRange.Font.Italic = True
ActivePresentation.Slides(1).Shapes(1).TextFrame _
.TextRange.Font.Italic = True
使用 HasTextFrame 属性判断形状是否含有文本框,并使用 HasText 属性判断该文本框是否包含文本,如以下示例所示。
Set myDocument = ActivePresentation.Slides(1)
For Each s In myDocument.Shapes
If s.HasTextFrame Then
With s.TextFrame
If .HasText Then MsgBox .TextRange.Text
End With End If Next
使用 TextFrame 对象的 TextRange 属性返回任意指定形状的 TextRange 对象。使用 Text 属性返回 TextRange 对象中的文本字符串。以下示例向 myDocument 中添加一个矩形并设置其包含的文本
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250, 140) _
.TextFrame.TextRange.Text = \"Here is some test text\"
使用 HasTextFrame 属性判断形状是否含有文本框,然后使用 HasText 属性判断该文本框是否包含文本。
使用 Selection 对象的 TextRange 属性返回当前选定的文字。以下示例将选定内容复制到剪贴板。
ActiveWindow.Selection.TextRange.Copy
使用下列方法之一可返回 TextRange 对象中的部分文本:Characters、Lines、Paragraphs、Runs、Sentences 或 Words。
使用 Find 和 Replace 方法可查找和替换文本范围内的文本。
使用下列方法之一可向 TextRange 对象中插入字符:InsertAfter、InsertBefore、InsertDateTime、InsertSlideNumber 或 InsertSymbol。
本示例创建活动演示文稿中第一张幻灯片的一个副本,然后设置
新幻灯片的背景阴影和标题文本。新幻灯片将作为演示文稿的第二张幻灯片。
Set newSlide = ActivePresentation.Slides(1).Duplicate
With newSlide
.Background.Fill.PresetGradient msoGradientVertical, _
1, msoGradientGold
.Shapes.Title.TextFrame.TextRange _
.Text = \"Second Quarter Earnings\"
End With
增加回车换行控制符
Chr(13) & Chr(10)
因篇幅问题不能全部显示,请点此查看更多更全内容