-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertVideos.pptm
More file actions
53 lines (39 loc) · 1.45 KB
/
insertVideos.pptm
File metadata and controls
53 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Sub InsertAudioAndSetSlideTime()
' 遍历文件夹中的文件,为了获取权限
Dim fileName0 As String
fileName0 = Dir(ActivePresentation.Path & "*.mp3")
' 这替换为你的音频文件夹路径
Dim baseFilePath As String
baseFilePath = "/Users/june/Work/ppt2video"
' 使用VBA读取文本文件
Dim textLines() As String, myFile As Integer
Dim timeFilePath As String
myFile = FreeFile()
timeFilePath = baseFilePath & "/times.txt"
Open timeFilePath For Input As myFile
textLines = Split(Input$(LOF(myFile), myFile), vbLf)
Close myFile
' 插入音频
Dim sld As Slide
Dim audioFile As String
For Each sld In ActivePresentation.Slides
audioFile = baseFilePath & "/video_" & sld.SlideNumber & ".wav"
sld.Shapes.AddMediaObject2 audioFile, msoFalse, msoTrue
Dim shp As Shape
Set shp = sld.Shapes(sld.Shapes.Count)
shp.AnimationSettings.PlaySettings.HideWhileNotPlaying = msoTrue
shp.AnimationSettings.PlaySettings.PlayOnEntry = True
' 设置音频对象的位置
shp.Top = 0 ' 设置垂直位置为 0 磅
shp.Left = -70 ' 设置为负数便于导出ppt时不显示音频对象
' 设置时长
If IsNumeric(textLines(sld.SlideIndex - 1)) Then
sld.SlideShowTransition.AdvanceTime = CLng(textLines(sld.SlideIndex - 1))
Else
MsgBox "行号" & sld.SlideIndex & "包含非数字"
End If
' 设置切换类型为自动换片
sld.SlideShowTransition.EntryEffect = ppEffectCut
sld.SlideShowTransition.AdvanceOnTime = msoTrue
Next sld
End Sub