2017-08-30 2 views
0

マクロでPowerPointのメディアオブジェクトの音楽を変更したいだけです。私はスライドで音楽を持っていますが、私はそれをどのように違う音楽に変えることができないのか分かりません。それとも新しいもので置き換えることも可能ですが、同じプロパティで置き換えることはできますか? あなたは必要に応じてプロパティをコピーし、既存の形状を削除し、新しいものと交換する必要があるとしている私は、次のコードで遊んでみましたが、私は残りの部分を知らない...メディアオブジェクトを変更する(VBA PowerPoint)

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

答えて

0

This MSDN articleは、MediaFormatプロパティの一部(すべて?)を列挙します。 this articleからの助けを借りて

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 = ...上記参照)効果を作成することで、自動的に再生するオーディオを得ることができます。

+0

ありがとうございます。しかし、私は「バックグラウンド再生」をどのように変更するか(各スライドのバックグラウンドで再生できるように)、さらにもう1つだけ必要です。 –

+0

@DanielClímacoオブジェクトプロパティを表示するためにVBEのLocalsウィンドウを使用すると、 'newShp.AnimationSettings.PlaySettings'で行うことができます。 –

+0

プロパティを見つけることができません "スライド間の再生"、それは私が欲しいものです(ちょうど名前を忘れた) –

関連する問題