2016-11-18 46 views
0

我试图改变WMV视频到MP4在这个宏改变在PowerPoint西元:错误使用VBA

Sub mp4_to_wmv() 
    Dim src, ptrn, re, Match, Matches 
    ptr1 = "(\w+)" 

    Create the regular expression. 
    Set re = CreateObject("vbscript.regexp") 
    re.Pattern = ptr1 
    re.IgnoreCase = False 
    re.Global = True 

    For Each pptSlide In ActivePresentation.Slides 
     For Each pptShape In pptSlide.Shapes 
      'If it's a video 
      If pptShape.Type = msoMedia Then 
       Set Matches = re.Execute(pptShape.Name) 
       ' If the video is mp4 then we create the wmv video 
       If Matches(1).Value = "mp4" Then 
        ' We delete the mp4 video 
        pptShape.Delete 
        ' We create the video 
        MyDocument = ActivePresentation.Path & "\" & Matches(0).Value & ".wmv" 
        ' The insertion part is the part giving me trouble, 
        Set Test = pptShape(FileName:=myDocument, Left:=156, Top:=0, Width:=2048, Height:=922) 
        ' Once we have the new video, we have to configure it to start automatically 
        Set oEffect = myDocument.TimeLine.MainSequence.AddEffect(myDocument.Shapes(3), msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious) 
        ' I'm not sure this part works... 
        With Test.AnimationSettings.PlaySettings 
         .PlayOnEntry = True 
         .LoopUntilStopped = msoCTrue 
        End With 
       End If 
      End If 
     Next 
    Next 
End Sub 

我试图做的是插入该工作示例进入死循环,但我我不能够做正确

Set myDocument = ActivePresentation.Slides(1) 

myDocument.Shapes.AddMediaObject FileName:="C:\Windows\clock.avi",Left:=5, Top:=5, Width:=100, Height:=100 

我想我必须在当前文件夹中两个视频WMV和MP4。 任何帮助,将不胜感激。

+0

你得到了什么样的错误(数量和在哪一行)。你是否声明了'myDocument'变量(以哪种方式)? –

+0

最后搞清楚了,我把AddMediaObject问题带入循环 – Angrod

回答

0
Sub mp4_to_wmv_or_wmv_to_mp4() 
Dim src, ptrn, re, Match, Matches 
ptr1 = "(\w+)" 

' Create the regular expression. 
Set re = CreateObject("vbscript.regexp") 
re.Pattern = ptr1 
re.IgnoreCase = False 
re.Global = True 

For Each pptSlide In ActivePresentation.Slides 
    For Each pptShape In pptSlide.Shapes 
     'If it's a video 
     If pptShape.Type = msoMedia Then 
      Set Matches = re.Execute(pptShape.Name) 
      ' If the video is mp4 then we create the wmv video 
      If Matches(1).Value = "mp4" Then 
       ' We load the video 
       MyDocument = ActivePresentation.Path & "\" & Matches(0).Value & ".wmv" 
      ElseIf Matches(1).Value = "wmv" Then 
       MyDocument = ActivePresentation.Path & "\" & Matches(0).Value & ".mp4" 
      ' The insertion part is the one giving me trouble, I know this works, but I am not able to integrate it within the loop 
       'Set myDocument = ActivePresentation.Slides(1) 
       'myDocument.Shapes.AddMediaObject FileName:="C:\Windows\clock.avi",Left:=5, Top:=5, Width:=100, Height:=100 
      Set test = pptSlide.Shapes.AddMediaObject(FileName:=MyDocument, Left:=156, Top:=0, Width:=2048, Height:=922) 
      ' Once we have the new video, we have to configure it to start automatically 
      'Set oEffect = myDocument.TimeLine.MainSequence.AddEffect(myDocument.Shapes(3), msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious) 
      ' I'm not sure this part works... 
      With test.AnimationSettings.PlaySettings 
       .PlayOnEntry = msoTrue 
       .LoopUntilStopped = msoCTrue 
       '.fullScreen = True 
      End With 
      End If 
     End If 
    Next 
Next 
End Sub 
0

这将是沿着这些路线的东西:

'Add the shape on the correct slide 
    Set newVideoShape = pptSlide.Shapes.AddMediaObject(FileName:=MyDocument, Left:=156, Top:=0, Width:=2048, Height:=922) 
    'Add the effect 
    Set oEffect = pptSlide.TimeLine.MainSequence.AddEffect(newVideoShape, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious) 
    'Make it the first animation 
    oEffect.MoveTo 1 

我会避免使用AnimationSettings对象的任何东西。当一个形状只能有一个入口动画时,它是一个传统的动画对象(PPT 2000及更早版本)。已知使用它会导致一些意想不到的结果;有时甚至会删除幻灯片上分配的所有动画。

+0

感谢提示,有三个问题: 1)我刚刚意识到我的代码链接了视频,我需要它们嵌入,你知道有什么变化我必须做什么? 2)你知道如何添加全屏效果吗? 谢谢! 3)你知道如何添加LoopUntilStopped效果吗? – Angrod

+0

对1的回答是使用AddMediaObject2我认为...我会继续挖掘全屏和循环效果。 – Angrod