使用vba中的regex在Powerpoint中更改视频名称

时间:2016-11-14 11:38:21

标签: video powerpoint-vba

我正在尝试搜索演示文稿中的所有视频并更改每个视频的扩展名;从XXXX.mp4更改为XXXX.wmv,反之亦然但每当我到达正则表达式部分时,我在“pptShape.LinkFormat.SourceFullName”上出现错误

Sub Test()

    Dim pptSlide As Slide
    Dim pptShape As Shape
    Dim Regx As Object
    Dim regX_matches As Object


    Set Regx = CreateObject("vbscript.regexp")
    With Regx
        .Global = True
        .Pattern = ".*"
    End With

    For Each pptSlide In ActivePresentation.Slides
        For Each pptShape In pptSlide.Shapes
            If pptShape.Type = msoMedia Then
                If pptShape.MediaType = ppMediaTypeMovie Then
                    Set regX_matches = Regx.Execute(pptShape.LinkFormat.SourceFullName)
                    Debug.Print "TEST '" + regX_matches + "'"
                    If regX_matches <> "" Then
                        pptShape.LinkFormat.SourceFullName = regX_matches(0) + ".mp4"
                    End If
                End If
            End If
        Next pptShape
    Next pptSlide

End Sub

任何提示?

提前致谢

Edit1:我的视频是嵌入式的,因为JamieG说pptShape.LinkFormat.SourceFullName不起作用...知道如何修改嵌入式视频吗?

1 个答案:

答案 0 :(得分:0)

错误是什么?我设法通过尝试返回嵌入(未链接)视频的SourceFullName属性来生成以下错误,那么您的视频是否已链接或嵌入?

LinkFormat (unknown member) : Invalid request. This operation requires a linked object.

您可以使用以下形状属性为此添加测试:

pptShape.MediaFormat.IsLinked

所以:

子测试()

Dim pptSlide As Slide
Dim pptShape As Shape
Dim Regx As Object
Dim regX_matches As Object


Set Regx = CreateObject("vbscript.regexp")
With Regx
    .Global = True
    .Pattern = ".*"
End With

For Each pptSlide In ActivePresentation.Slides
    For Each pptShape In pptSlide.Shapes

        If pptShape.Type = msoMedia Then
            If pptShape.MediaType = ppMediaTypeMovie And pptShape.MediaFormat.IsLinked Then
                Set regX_matches = Regx.Execute(pptShape.LinkFormat.SourceFullName)
                Debug.Print "TEST '" + regX_matches + "'"
                If regX_matches <> "" Then
                    pptShape.LinkFormat.SourceFullName = regX_matches(0) + ".mp4"
                End If
            End If
        End If
    Next pptShape
Next pptSlide

End Sub