一、使用 Comment 对象
使用 Comments(index)(其中 index 为批注的编号)或 Item 方法访问幻灯片上的单个批注。本示例显示第一张幻灯片上第一个批注的作者。如果没有批注,将显示一条消息进行声明。
Sub ShowComment()
With ActivePresentation.Slides(1).Comments
If .Count > 0 Then
MsgBox "The first comment on this slide is by " & _
.Item(1).Author
Else
MsgBox "There are no comments on this slide."
End If
End With
End Sub
使用以下属性访问批注数据:
Author 作者的全名
AuthorIndex 作者在批注列表中的索引
AuthorInitials 作者姓和名的首字母
DateTime 创建批注的日期和时间
Text 批注的文本
Left、Top 批注的屏幕坐标
本示例显示一条消息,其中包含第一张幻灯片上所有批注的作者、日期、时间和内容。
Sub SlideComments()
Dim cmtExisting As Comment
Dim cmtAll As Comments
Dim strComments As String
Set cmtAll = ActivePresentation.Slides(1).Comments
If cmtAll.Count > 0 Then
For Each cmtExisting In cmtAll
strComments = strComments & cmtExisting.Author & vbTab & _
cmtExisting.DateTime & vbTab & cmtExisting.Text & vbLf
Next
MsgBox "The comments in your document are as follows:" & vbLf _
& strComments
Else
MsgBox "This slide doesn't have any comments."
End If
End Sub
二、使用 Comments 集合
使用 Comments 属性引用 Comments 集合。以下示例显示当前幻灯片上批注的编号。
Sub CountComments()
MsgBox "You have " & ActiveWindow.Selection.SlideRange(1) _
.Comments.Count & " comments on this slide."
End Sub
使用 Add 方法在幻灯片中添加一个批注。本示例在当前演示文稿的第一张幻灯片中添加一个新批注。
Sub AddComment()
Dim sldNew As Slide
Dim cmtNew As Comment
Set sldNew = ActivePresentation.Slides.Add(Index:=1, _
Layout:=ppLayoutBlank)
Set cmtNew = sldNew.Comments.Add(Left:=12, Top:=12, _
Author:="Jeff Smith", AuthorInitials:="JS", _
Text:="You might consider reviewing the new specs " & _
"for more up-to-date information.")
End Sub