繁体   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