你将需要一个新的删除现有的形状和替换它,复制性需要。 This MSDN article列举了MediaFormat
属性的一些(全部?)。
Option Explicit
Sub ReplaceMediaFormat()
Dim sld As Slide
Dim newShp As Shape
Dim shp As Shape
Dim mf As MediaFormat
Dim path As String
Set sld = ActivePresentation.Slides(1) '// Modify as needed
Set shp = sld.Shapes("bg_music")
Set mf = shp.MediaFormat
'// Modify the path for your new media file:
path = "C:\Users\david.zemens\Downloads\2540.mp3"
Set newShp = sld.Shapes.AddMediaObject2(path)
With newShp
.Top = shp.Top
.Left = shp.Left
.Width = shp.Width
.Height = shp.Height
' etc...
End With
' // copy the mediaformat properties as needed
With newShp.MediaFormat
.StartPoint = mf.StartPoint
.EndPoint = mf.EndPoint
.FadeInDuration = mf.FadeInDuration
.FadeOutDuration = mf.FadeOutDuration
.Muted = mf.Muted
.Volume = mf.Volume
' etc...
End With
'// remove the original
shp.Delete
Dim eff As Effect
'// Creates an effect in the timeline which triggers this audio to play when the slideshow begins
Set eff = sld.TimeLine.MainSequence.AddEffect(newShp, msoAnimEffectMediaPlay, trigger:=msoAnimTriggerWithPrevious)
With newShp.AnimationSettings.PlaySettings
.LoopUntilStopped = msoCTrue
.PauseAnimation = msoFalse
.PlayOnEntry = msoCTrue
.RewindMovie = msoCTrue
.StopAfterSlides = 999
.HideWhileNotPlaying = msoTrue
End With
与this article的帮助下,我能得到的音频,以通过创建效果(见上Set eff = ...
)自动播放。
好的,谢谢。但我只需要再做一件事,如何将“背景播放”更改为真(使其在背景中,每张幻灯片中播放)? –
@DanielClímaco如果你使用VBE中的Locals窗口来查看对象属性,它看起来像你可以通过'newShp.AnimationSettings.PlaySettings'来实现。 –
我无法找到属性“玩/通过幻灯片之间”,这就是我想要的(只是忘了名字) –