6 个回答
一、Windows 和 Mac OS 通用的方法
一种比较通用的方法是 VBA 代码,优点是比较通用,缺点是每次使用都需要在Visual Basic 编辑器里面新建模块,而且保存的时候一不小心可能将宏代码也包含在原文稿当中。
在 Windows 版 PPT中打开 Visual Basic 编辑器的方法如下:
在 Mac 版 PPT 中打开 Visual Basic 编辑器的方法如下:
打开 Visual Basic 编辑器后,只需要在顶部菜单栏中点击「插入」→「模块」,然后在新出现的文本框中输入下列 VBA 代码,再点击窗口上方的三角形按钮来运行代码即可:
上面用到的 VBA 代码 [1] 如下:
Sub RemoveAllSpeakerNotes()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
sld.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange = ""
Next sld
End Sub
二、适用于 Mac OS 的方法(便于重复使用)
在 Mac OS 上我们还可以用 AppleScript +「自动操作/Automator」的方法来实现,好处是一旦创建好「服务」,以后就可以方便地反复使用。
首先打开 「自动操作/Automator」 ,选择新建一个 「服务/Quick Action」 :
然后在左侧栏中选择「运行 AppleScript」,并拖入右侧空白处,在新出现的编辑框中填入下图中的代码,然后按照下图操作将 workflow 设置为仅在 Microsoft PowerPoint 中生效即可:
最后 control + S 保存为“清除当前演示文稿中的所有备注”。
此时再打开 PowerPoint,并点击顶部菜单栏的「PowerPoint」→「服务/Services」→「清除当前演示文稿中的所有备注」即可:
演示效果如下:
上面用到的 AppleScript 代码如下:
on run {input, parameters}
tell application "Microsoft PowerPoint" -- version: 2019
set allSlides to slides of active presentation
set counter to 0
repeat with each_slide in allSlides
set content of text range of text frame of place holder 2 of notes page of each_slide to ""
on error
set counter to counter + 1
end try
end repeat
if counter > 0 then display dialog "共跳过" & counter & "个无法解析的ppt页" buttons {"OK"} default button 1 with title "清除当前演示文稿中的所有备注" with icon note
end tell
return input
end run
上面介绍的两种方法都是支持撤销的(比如按下 ctrl + Z / command + Z)。
【更新】
补充一下「将 PPT 备注导出为 txt 文件」的脚本:
1. VBA 代码(适用于 Windows 和 Mac)
如果不想要导出全部幻灯片的备注,可以在代码里面修改页码范围,即把下面的代码
For i = 1 To num_slides
修改成你想要的范围(如第 4 页 到第 8 页):
For i = 4 To 8
Sub ExportNote()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
iFile = FreeFile 'Get a free file number
Dim PathSep As String
Dim path As String
Dim FileNum As Integer
Dim sTempString As String
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
filename = oPres.FullName
#If Mac Then
PathSep = "/"
path = MacScript("return POSIX path of (path to desktop folder)")
if Right(path, 1) = PathSep And Len(path) > 1 Then
path = Mid(path, 1, Len(path) - 1)
End If
#Else
PathSep = "\"
path = oPres.Path
#End If
FileNum = FreeFile
'Open output file
' NOTE: errors here if file hasn't been saved
Open path & PathSep & filename & ".txt" For Output As FileNum
On Error GoTo ErrorHandler ' Enable error-handling routine.
num_slides = ActivePresentation.Slides.Count
For i = 1 To num_slides
Set oSld = ActivePresentation.Slides(i)
Print #iFile, "(Page " & CStr(oSld.SlideNumber) & ")" & vbNewLine
Print #iFile, oSld.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange
Print #iFile, "--------------------------" & vbNewLine & vbNewLine & vbNewLine
Next i
Close #iFile
MsgBox "文件已创建在'" & path & PathSep & filename & ".txt'"
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Print #iFile, "(Error)" & vbNewLine
Resume Next ' Resume execution at the statement immediately
' following the statement where the error occurred.
End Sub
演示效果:
运行之后会自动在 桌面 上生成 同名 的 txt 文件,其中包含提取出的每一页幻灯片的备注内容。
注:如果其中某些幻灯片的备注提取失败,则 txt 文件中会显示类似以下的信息:
(Page 2)
(Error)
--------------------------
2. AppleScript 代码(适用于 Mac)
on pptGetAllNote(page_from as integer, page_to as integer)
set delimit to "--------------------------"
tell application "Microsoft PowerPoint"
activate
set counter to 0
set total_text to ""
repeat with slideNumber from page_from to page_to
set page_text to "(Page " & (slideNumber as text) & ")
tell slide slideNumber of active presentation
set page_note to content of text range of text frame of place holder 2 of notes page
on error
set page_note to "(Error)"
set counter to counter + 1
end try
set page_text to (page_text & page_note & "
" & delimit & "
set total_text to total_text & page_text & "
end tell
end repeat
end tell
return total_text
end pptGetAllNote
on validateInt(str_number as text)
set N to str_number as integer
return {0, N}
on error number errorNumber
return {-1, -1}
end try
end validateInt
on validateInput(page_from_to as text, num_slides as integer)
set {flag, page_from, page_to} to {-1, -1, -1}
set oldDelims to my text item delimiters -- save the current delimiters
set my text item delimiters to {"-", "~", "~"} -- the character to split on
set num to (count of text items of page_from_to)
if num = 1 then
# single page
set {flag1, page_from} to my validateInt(first text item of page_from_to)
if flag1 = 0 and page_from > 0 and page_from ≤ num_slides then set {flag, page_to} to {0, page_from}
else if num = 2 then
# multiple pages
set {flag1, page_from} to my validateInt(first text item of page_from_to)
set {flag2, page_to} to my validateInt(second text item of page_from_to)
if flag1 = 0 and flag2 = 0 and page_from > 0 and page_from ≤ num_slides and page_from ≤ page_to and page_to > 0 and page_to ≤ num_slides then set flag to 0
end if
set my text item delimiters to oldDelims -- just to be safe, restore the old delimiters
return {flag, page_from, page_to}
end validateInput
on run {input, parameters}
set userLocale to user locale of (system info)
tell application "Microsoft PowerPoint" -- version: 2019
set ppt_name to name of active presentation
set num_slides to count of slides of active presentation
set cur_page to slide number of slide of view of active window
if cur_page is missing value then
set tips to ""
set tips to "
[当前页码为 " & cur_page & "]"
end if
if num_slides = 1 then
set default_ans to "1"
set default_ans to "1-" & (num_slides as text)
end if
set page_from_to to the text returned of (display dialog "请输入要处理的 PPT 页码范围" & tips & ":" default answer default_ans with title "提取 PPT 文本框内容" with icon note)
set {flag, page_from, page_to} to my validateInput(page_from_to, num_slides)
repeat while flag ≠ 0
set page_from_to to the text returned of (display dialog "请输入要处理的 PPT 页码范围
[请确保页码范围有效]:" default answer default_ans with title "提取 PPT 文本框内容" with icon caution)
set {flag, page_from, page_to} to my validateInput(page_from_to, num_slides)
end repeat
end tell
set content_to_write to pptGetAllNote(page_from, page_to)
set filename to POSIX path of (((path to desktop folder) as text) & ppt_name & ".txt")
tell application "TextEdit"
activate
set newDoc to (make new document with properties {text:(content_to_write as Unicode text)})
end tell
do shell script "cat > " & filename & " << 'EOF'