2013-07-19 30 views
0

我想查看視頻是否使用vba鏈接。爲此,我檢查了形狀的參數,並且看到我的視頻已鏈接LinkFormat參數已啓用,並且未啓用。問題是,如果我檢查LinkFormat時,它不是一個鏈接的視頻,我收到一個錯誤「對象不存在」。我只是想檢查它是否存在或沒有錯誤。如何知道形狀參數是否存在

我試圖把一個錯誤處理程序,但無論如何,它給我的錯誤。

編輯:下面我把我怎麼樣我試圖用我接受這個職位的建議,使之:

For Each sld In ActivePresentation.Slides 

    For i = 1 To sld.Shapes.count 

     If sld.Shapes(i).Type = msoMedia Then 

       If hasVideo = False Then 
        hasVideo = True 
       End If 
       videoNum = videoNum + 1 

        If sld.Shapes(i).MediaType = ppMediaTypeMovie Then 
         If CSng(Application.Version) < 14 Then 
          If hasVideo = False Then 
           hasVideo = True 
          End If 
          videoNum = videoNum + 1 
         Else 
          If sld.Shapes(i).MediaFormat.IsEmbedded Then 
           If hasVideo = False Then 
            hasVideo = True 
           End If 
           videoNum = videoNum + 1 
          Else 
           MsgBox "linked videos are not supported and won't be shown"         
          End If 
         End If 
        End If 
     End If 
    Next i 
    Next 
+0

顯示你的代碼,如果可能的話... – dee

回答

0
Sub TestVideos() 
    ' oSh as Object rather than as Shape so it'll work 
    ' in earlier versions of PPT that don't have some of these 
    ' properties 
    Dim oSh As Object 
    Dim oSl As Slide 

    ' because my test file has two videos 
    ' on slide 1 ... 
    Set oSl = ActivePresentation.Slides(1) 

    For Each oSh In oSl.Shapes 
     If oSh.Type = msoMedia Then 
      If oSh.MediaType = ppMediaTypeMovie Then 
       If CSng(Application.Version) < 12 Then 
        ' This is PPT 2003 or earlier; all vids are embedded 
        MsgBox "This video is embedded" 
       Else 
        If oSh.MediaFormat.IsEmbedded Then 
         MsgBox "This video is embedded" 
        Else 
         MsgBox "This video is linked" 
        End If 
       End If 
      End If 
     End If 
    Next 

End Sub 
+0

得益於它完美! –

+0

最後,我發現了一個在這些行中給我一個錯誤的簡報。它在其他如果CSng(Application.Version)<12和其他如果oSh.MediaFormat.IsEmbedded它然後它給我一個錯誤,因爲MediaFormat不存在。 –

+0

我的錯誤:應該是<14而不是<12。14 = PPT 2010,第一個開始嵌入視頻的版本。 –

相關問題