我需要制作一个很长的视频教程,YouTube有一个伟大的功能,视频描述是自动解析的hh:mm:ss在行的开头,以允许观众转到视频中的特定时间。有没有办法自动使用VBA和powerpoint的对象模型来生成带有幻灯片标题的计时?
发布于 2020-08-27 15:40:32
下面的脚本似乎可以完成这项工作。我在https://www.rdpslides.com/pptfaq/FAQ00033_How_do_I_use_VBA_code_in_PowerPoint.htm上找到了关于如何在powerpoint中运行VBA的最清晰的说明。它是基于https://www.rdpslides.com/pptfaq/FAQ00413_Show_me_the_transition_time_of_each_slide_and_total_running_time_of_the_show.htm的
Sub PowerPointYouTubeTiming()
' Copyright/Last Edited 11 December, 2019 by Stepen Rindsberg dba PPTools
' Modified by T Delbruck for powerpoint youtube timing 26.8.2020
Dim oSld As Slide
Dim strMessage As String
Dim lngTotalTime As Long
lngTotalTime = 0
' Use this to collect times for ALL slides:
For Each oSld In ActivePresentation.Slides
' Or comment it out and uncomment this to get just the selected slides:
' For Each oSld in ActiveWindow.Selection.SlideRange
strMessage = strMessage _
& Format(lngTotalTime \ 3600, "00") & ":" & Format((lngTotalTime Mod 3600) \ 60, "00") & ":" & Format(lngTotalTime Mod 60, "00") _
& vbTab _
& CStr(oSld.SlideNumber) _
& vbTab
If oSld.Shapes.HasTitle Then
strMessage = strMessage _
& oSld.Shapes.Title.TextFrame.TextRange.Text & vbCrLf
Else
strMessage = strMessage & vbCrLf
End If
lngTotalTime = lngTotalTime + oSld.SlideShowTransition.AdvanceTime
Next oSld
' Comment these out if you don't want to see them
' MsgBox strMessage
' MsgBox ("Total time: " & CStr(lngTotalTime))
' And if you want to write the results to a text file:
Dim FileNum As Integer
Dim FileName As String
' Edit this to suit, especially if you use a Mac:
' As written, it'll pick up your TEMP folder location automatically:
FileName = Environ$("TEMP") & "\" & "YouTubeTimings.txt"
FileNum = FreeFile()
Open FileName For Output As FileNum
Print #FileNum, strMessage
' Print #FileNum, "Total time: " & Format((lngTotalTime), "hh:mm:ss")
Close #FileNum
' view the file in notepad
Call Shell("Notepad.exe " & FileName, vbNormalFocus)
' or if you use a mac, comment that out and open the file in any text editor you like
End Sub示例输出如下所示:
00:00:00 1 Title
00:00:56 2 heading slide 2
00:01:57 3 Your heading slide 3我在https://youtu.be/FP01jPau5dM做的YouTube描述中的计时结果。
有一件事我做不到,那就是总时间的格式化。我的VBA格式((LngTotalTime),"hh:mm:ss")总是在00:00:00出现。这就是在代码中手动将时间转换为hh、mm和ss的原因。
https://stackoverflow.com/questions/63611333
复制相似问题