你將需要一個新的刪除現有的形狀和替換它,複製性需要。 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'來實現。 –
我無法找到屬性「玩/通過幻燈片之間」,這就是我想要的(只是忘了名字) –