簡體   English   中英

更改媒體對象 (VBA PowerPoint)

[英]Change Media Object (VBA PowerPoint)

我只想使用宏更改 PowerPoint 中媒體對象的音樂。 我在幻燈片中有音樂,但我不知道如何將其更改為不同的音樂。 或者是否可以用新的但具有相同屬性的替換它......? 我嘗試使用以下代碼,但我不知道其余的......

Slide3.Shapes("bg_music").MediaFormat. 'code that I don't know to change it's music/media

您將需要刪除現有形狀並將其替換為新形狀,並根據需要復制屬性。 這篇 MSDN 文章列舉了一些(全部?) 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

這篇文章的幫助下,我可以通過創建一個效果來讓音頻自動播放(參見上面的Set eff = ... )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM